package hotel.switchs.oversea.online.service.impl;

import com.alibaba.fastjson.JSON;
import hotel.base.oversea.constant.CallbackConstants;
import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.constant.CommonUrlConstants;
import hotel.base.oversea.constant.enums.*;
import hotel.base.oversea.dto.switchs.SwitchMasterHotelInfoDto;
import hotel.base.oversea.entity.SwitchHotelActiveTagEntity;
import hotel.base.oversea.entity.SwitchPriceBaseSetEntity;
import hotel.base.oversea.service.impl.BaseServiceImpl;
import hotel.base.oversea.utils.*;
import hotel.base.oversea.vo.BatchPushRoomDatasVo;
import hotel.base.oversea.vo.meituan.request.goods.MtHotelGoodsStatusDetailStateVo;
import hotel.base.oversea.vo.meituan.response.goods.MtHotelGoodsCancelRuleReturnVo;
import hotel.base.oversea.vo.meituan.response.goods.MtHotelGoodsInventoryVo;
import hotel.base.oversea.vo.meituan.response.goods.MtHotelGoodsPriceBaseDetailVo;
import hotel.base.oversea.vo.meituan.response.goods.MtfpHotelGoodsCancelRuleVo;
import hotel.switchs.oversea.api.VO.SellingRuleVo;
import hotel.switchs.oversea.api.VO.request.*;
import hotel.switchs.oversea.api.entity.*;
import hotel.switchs.oversea.online.config.service.RedisService;
import hotel.switchs.oversea.online.mapper.*;
import hotel.switchs.oversea.online.service.SwitchBasicRoomTypeService;
import hotel.switchs.oversea.online.service.SwitchPushRoomService;
import hotel.switchs.oversea.online.service.SwitchRoomPriceService;
import hotel.switchs.oversea.online.service.SwitchRoomPriceSetService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.tomcat.util.threads.ThreadPoolExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

/**
 * @Author lmf
 * @Date 2020/6/17 17:33
 **/
@Slf4j
@Service
public class SwitchPushRoomServiceImpl extends BaseServiceImpl implements SwitchPushRoomService {

    @Autowired
    private SwitchRestTempaleUtilsService switchRestTempaleUtilsService;

    @Autowired
    private SwitchCreateRoomMapper switchCreateRoomMapper;

    @Autowired
    private SwitchBasicRoomTypeService switchBasicRoomTypeService;

    @Autowired
    private SwitchRoomOnlineOfflineLogMapper switchRoomOnlineOfflineLogMapper;

    @Autowired
    private SwitchPushRoomDataMapper switchPushRoomDataMapper;

    @Autowired
    private SwitchRoomPriceService switchRoomPriceService;

    @Autowired
    private SwitchMasterHotelInfoMapper switchMasterHotelInfoMapper;

    @Autowired
    private SwitchSetRoomSaleRuleMapper switchSetRoomSaleRuleMapper;

    /**
     * 价格配置
     */
    @Autowired
    private SwitchRoomPriceSetService switchRoomPriceSetService;

    /**
     * @author: lmf
     * @date: 2020/8/17 17:37
     * 活动读取
     */
    @Autowired
    private SwitchHotelActiveTagMapper switchHotelActiveTagMapper;

    @Autowired
    RedisService redisService;
    @Autowired
    private SwitchCreateSubHotelMapper switchCreateSubHotelMapper;
    /**
     * 美团的地址
     */
    private static final String MEI_TUAN_URL = CommonUrlConstants.MEITUAN_HOST + "/";

    @Autowired
    private SwitchBaseSetMapper switchBaseSetMapper;

    /**
     * 推送价格记录表
     */
    private List<SwitchPushRoomDataAllEntity> switchPushRoomDataEntities = new ArrayList<>();

    /**
     * 推送房态记录表
     */
    private List<SwitchPushRoomDataAllEntity> switchPushStatusEntities = new ArrayList<>();
    /**
     * 母酒店信息
     * key :母酒店id  value 母酒店信息
     */
    private Map<String, SwitchMasterHotelInfoDto> masterHotelInfoDtoMap = new HashMap<>();


    //定义多线程启动相关配置
    //定义线程池数量
    private static int corePoolSize = Runtime.getRuntime().availableProcessors();
    //corePoolSize：线程池持有的可用的线程数量
    //maximumPoolSize：当队列workQueue满了过后，线程池可用的最大线程数量
    private static ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, Integer.MAX_VALUE, 101, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1000));
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    SwitchPriceBaseSetMapper switchPriceBaseSetMapper;

    @Autowired
    SwitchHotelUpLogMapper switchHotelUpLogMapper;



    /**
     * 异步处理 每秒一次
     * 多个房型涉及的天数不能大于300（房型个数*天数）。推送的数据均为异步处理，处理结果不会马上返回。
     * 新建的房型请延迟6分钟以上推送数据，否则数据可能会有问题（系统有缓存，会有一定延迟导致）。
     * 接口有重复性检验，开始日期+结束日期+渠道+具体的数据，如果和上次一样，会报重复的错。
     * 注意:
     * 1.如果美团房态变为不可预定，应该进行下架
     * 2.如果售卖房型是下架的房型，如果房态变为可预订需要重新上架
     * 该接口包含取消规则 房态 价格 推送 2020-12-17 接口限制暂时不调用美团的房态接口，让美团主动来推送
     * @param hotelId         子酒店id
     * @param basicRoomTypeId 售卖房型id
     * @return
     */
    @Override
    @Transactional
    public Result<Object> pushRoomData(int hotelId, int basicRoomTypeId, int genre) {
        //1.获取对应的产品id
        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectGoods(hotelId, basicRoomTypeId);
        if (ObjectUtils.isEmpty(switchCreateRoomEntity)) {
            log.info("============找不到相应的创建售卖房型记录，请检查售卖房型id正确=======");
            return new Result<>("找不到相应的创建售卖房型记录，请检查售卖房型id正确");
        }
        //获取该房型推送最后一天的日期
        SwitchPushRoomDataEntity switchPushRoomDataEntity = switchPushRoomDataMapper.getLastPushDate(hotelId, basicRoomTypeId);
        Map<String, Object> params = new HashMap<>();
        int day=3;
        String lastTime=DateUtil.getNextDays(day);
        String endTime=lastTime;
        //如果不存在说明第一次推送房量，此时库存应该是add
        if (ObjectUtils.isEmpty(switchPushRoomDataEntity) || StringUtils.isEmpty(switchPushRoomDataEntity.getStartTime())) {
            params.put("days", day);
        } else {
            if (genre > 0) {//如果genre=1 表示重复推送,从今天开始重新推一个月的价格数据
                params.put("days", day);
            } else {//表示增量推送 比如上次推送到9月1号 这次就从9月1号继续推
                /*String endTime= DateUtil.getNextDay(switchPushRoomDataEntity.getStartTime());
                params.put("startDate", DateUtil.getNextDay(switchPushRoomDataEntity.getStartTime()));
                params.put("endDate", DateUtil.getNextMothesDay(switchPushRoomDataEntity.getStartTime()));
                params.put("checkinDate", DateUtil.getNextDay(switchPushRoomDataEntity.getStartTime()));
                params.put("checkoutDate", DateUtil.getNextMothesDay(switchPushRoomDataEntity.getStartTime()));*/
                //startTime>endTime false startTime<=endTime true
                if(!lastTime.equals(switchPushRoomDataEntity.getStartTime())){
                    params.put("days", day);
                }else{
                    return new Result<>("今日已经推送过不能重复推送");
                }
            }
            endTime=switchPushRoomDataEntity.getStartTime();
        }
        int mtGoodId = switchCreateRoomEntity.getMtGoodId();
        int mtHotelId = switchCreateRoomEntity.getMtHotelId();
        int mtRoomId = Integer.parseInt(switchCreateRoomEntity.getMtRoomId());
        //2.获取美团房价
        params.put("goodsId", mtGoodId);
        List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = getMtGoodsPrice(params);
        if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
            switchPushRoomDataMapper.deleteByRoomId(switchCreateRoomEntity.getRoomId());
            //如果有日志记录再进行操作
            switchPushRoomDataEntity=new SwitchPushRoomDataEntity();
            switchPushRoomDataEntity.setCreateTime(new Date());
            switchPushRoomDataEntity.setHotelId(hotelId);
            switchPushRoomDataEntity.setRoomId(switchCreateRoomEntity.getRoomId());
            switchPushRoomDataEntity.setId(StringUtil.getUUID());
            switchPushRoomDataEntity.setMasterHotelId(switchCreateRoomEntity.getMasterHotelId());
            switchPushRoomDataEntity.setModifyTime(new Date());
            switchPushRoomDataEntity.setMtGoodId(switchCreateRoomEntity.getMtGoodId());
            switchPushRoomDataEntity.setMtHotelId(switchCreateRoomEntity.getMtHotelId());
            switchPushRoomDataEntity.setMtRoomId(Integer.valueOf(switchCreateRoomEntity.getMtRoomId()));
            switchPushRoomDataEntity.setStartTime(lastTime);
            switchPushRoomDataMapper.insert(switchPushRoomDataEntity);
            log.info("美团的产品价格日历数据为空");
            return new Result<>("美团的产品价格日历数据为空");
        }
        //3.获取美团的房态
        params.put("hotelId", mtHotelId);
        List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos = getMtGoodsStatus(params, mtGoodId);
        log.info("===============房态的数据长度为ss{}======", mtHotelGoodsStatusDetailStateVos.size());
        if (mtHotelGoodsStatusDetailStateVos.size() < 1) {
            mtHotelGoodsStatusDetailStateVos = new ArrayList<>();
        }
        //4.获取美团的产品库存
     /*   params.put("roomId", mtRoomId);
        MtHotelGoodsInventoryVo mtHotelGoodsInventoryVo = getMtGoodsInventory(params);
        if (ObjectUtils.isEmpty(mtHotelGoodsInventoryVo)) {
            log.info("美团的产品库存为空");
            //return new Result<>("美团的产品库存为空");
        }*/
        //5.获取美团产品的取消规则
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
        params.put("checkinDate", simpleDateFormat.format(new Date()));
        params.put("checkoutDate", lastTime);
        params.put("mtHotelId",mtHotelId);
        params.put("mtGoodsId",mtGoodId);
        List<MtHotelGoodsCancelRuleReturnVo> mtHotelGoodsCancelRuleReturnVos=getMtHotelGoodsCancelRuleReturn(params);
        if(ObjectUtils.isEmpty(mtHotelGoodsCancelRuleReturnVos)||mtHotelGoodsCancelRuleReturnVos.size()<1){
            log.info("====酒店id{}产品id{}获取美团产品的取消规则为空========",mtHotelId,mtGoodId);
            return new Result<>("获取美团产品的取消规则");
        }
        BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
        batchPushRoomVo.setHotelId(hotelId);
        //5.封装房型推送数据实体
        List<RoomDataEntityVo> roomDataEntityVos = null;
        try {
            roomDataEntityVos = roomDataEntityVoV2(switchCreateRoomEntity, mtHotelGoodsPriceBaseDetailVos, mtHotelGoodsStatusDetailStateVos,  endTime,mtHotelGoodsCancelRuleReturnVos);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (ObjectUtils.isEmpty(roomDataEntityVos) || roomDataEntityVos.size() < 1) {
            log.info("推送的实体数据为空");
            return new Result<>("推送的实体数据为空");
        }
        //对日期时间相同的价格进行合并
        batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
        log.info("==============推送的房型数据实体为{}====================", roomDataEntityVos);
        Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
        if(result.getCode() == CommonConstants.SUCCESS||result.getMsg().toString().contains("数据重复")){
            switchPushRoomDataMapper.deleteByRoomId(switchCreateRoomEntity.getRoomId());
            //如果有日志记录再进行操作
            switchPushRoomDataEntity=new SwitchPushRoomDataEntity();
            switchPushRoomDataEntity.setCreateTime(new Date());
            switchPushRoomDataEntity.setHotelId(batchPushRoomVo.getHotelId());
            switchPushRoomDataEntity.setRoomId(switchCreateRoomEntity.getRoomId());
            switchPushRoomDataEntity.setId(StringUtil.getUUID());
            switchPushRoomDataEntity.setMasterHotelId(switchCreateRoomEntity.getMasterHotelId());
            switchPushRoomDataEntity.setModifyTime(new Date());
            switchPushRoomDataEntity.setMtGoodId(switchCreateRoomEntity.getMtGoodId());
            switchPushRoomDataEntity.setMtHotelId(switchCreateRoomEntity.getMtHotelId());
            switchPushRoomDataEntity.setMtRoomId(Integer.valueOf(switchCreateRoomEntity.getMtRoomId()));
            switchPushRoomDataEntity.setStartTime(DateUtil.getNextDays(day));
            switchPushRoomDataMapper.insert(switchPushRoomDataEntity);
            redisService.remove("quartz_switch_can_push_room_page_index");
        }
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/17
     * 推送取消规则
     */
    @Override
    @Transactional
    public Result<Object> pushRoomDataByCancel(int hotelId, int basicRoomTypeId, int genre) {
        //1.获取对应的产品id
        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectGoods(hotelId, basicRoomTypeId);
        if (ObjectUtils.isEmpty(switchCreateRoomEntity)) {
            log.info("============找不到相应的创建售卖房型记录，请检查售卖房型id正确=======");
            return new Result<>("找不到相应的创建售卖房型记录，请检查售卖房型id正确");
        }
        //获取该房型推送最后一天的日期
        SwitchPushRoomDataEntity switchPushRoomDataEntity = switchPushRoomDataMapper.getLastPushDate(hotelId, basicRoomTypeId);
        Map<String, Object> params = new HashMap<>();
        int day=3;
        if(redisService.isMember(CommonConstants.SWITCH_SALE_HOTEL_VIP,switchCreateRoomEntity.getMtHotelId())){
            day=getDaysCommonBaseSetForVip();
        }else{
            day=getDaysCommonBaseSetForNormal();
        }
        String lastTime=DateUtil.getNextDays(day);
        String endTime=lastTime;
        //如果不存在说明第一次推送房量，此时库存应该是add
        if (ObjectUtils.isEmpty(switchPushRoomDataEntity) || StringUtils.isEmpty(switchPushRoomDataEntity.getStartTime())) {
            params.put("days", day);
        } else {
            if (genre > 0) {//如果genre=1 表示重复推送,从今天开始重新推一个月的价格数据
                params.put("days", day);
            } else {//表示增量推送 比如上次推送到9月1号 这次就从9月1号继续推
                if(!lastTime.equals(switchPushRoomDataEntity.getStartTime())){
                    params.put("days", day);
                }else{
                    return new Result<>("今日已经推送过不能重复推送");
                }
            }
            endTime=switchPushRoomDataEntity.getStartTime();
        }
        int mtGoodId = switchCreateRoomEntity.getMtGoodId();
        int mtHotelId = switchCreateRoomEntity.getMtHotelId();
        //5.获取美团产品的取消规则
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
        params.put("checkinDate", simpleDateFormat.format(new Date()));
        params.put("checkoutDate", lastTime);
        params.put("mtHotelId",mtHotelId);
        params.put("mtGoodsId",mtGoodId);
        List<MtHotelGoodsCancelRuleReturnVo> mtHotelGoodsCancelRuleReturnVos=getMtHotelGoodsCancelRuleReturn(params);
        if(ObjectUtils.isEmpty(mtHotelGoodsCancelRuleReturnVos)||mtHotelGoodsCancelRuleReturnVos.size()<1){
            log.info("====酒店id{}产品id{}获取美团产品的取消规则为空========",mtHotelId,mtGoodId);
            return new Result<>("获取美团产品的取消规则");
        }
        BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
        batchPushRoomVo.setHotelId(hotelId);
        //5.封装房型推送数据实体
        List<RoomDataEntityVo> roomDataEntityVos = null;
        try {
            roomDataEntityVos = roomDataEntityVoCancel(switchCreateRoomEntity,mtHotelGoodsCancelRuleReturnVos);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (ObjectUtils.isEmpty(roomDataEntityVos) || roomDataEntityVos.size() < 1) {
            log.info("推送的实体数据为空");
            return new Result<>("推送的实体数据为空");
        }
        //对日期时间相同的价格进行合并
        batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
        log.info("==============推送的房型数据实体为{}====================", roomDataEntityVos);
        Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
        if(result.getCode() == CommonConstants.SUCCESS||result.getMsg().toString().contains("数据重复")){
            switchPushRoomDataMapper.deleteByRoomId(switchCreateRoomEntity.getRoomId());
            //如果有日志记录再进行操作
            switchPushRoomDataEntity=new SwitchPushRoomDataEntity();
            switchPushRoomDataEntity.setCreateTime(new Date());
            switchPushRoomDataEntity.setHotelId(batchPushRoomVo.getHotelId());
            switchPushRoomDataEntity.setRoomId(switchCreateRoomEntity.getRoomId());
            switchPushRoomDataEntity.setId(StringUtil.getUUID());
            switchPushRoomDataEntity.setMasterHotelId(switchCreateRoomEntity.getMasterHotelId());
            switchPushRoomDataEntity.setModifyTime(new Date());
            switchPushRoomDataEntity.setMtGoodId(switchCreateRoomEntity.getMtGoodId());
            switchPushRoomDataEntity.setMtHotelId(switchCreateRoomEntity.getMtHotelId());
            switchPushRoomDataEntity.setMtRoomId(Integer.valueOf(switchCreateRoomEntity.getMtRoomId()));
            switchPushRoomDataEntity.setStartTime(DateUtil.getNextDays(day));
            switchPushRoomDataMapper.insert(switchPushRoomDataEntity);
            redisService.remove("quartz_switch_can_push_room_page_index");
        }
        return new Result<>();
    }
    /**
     * 获取优势酒店天数
     * @return
     */
    public Integer getDaysCommonBaseSetForVip() {
        Integer returnDays;
        String daysCom = (String)redisService.get(CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS);
        if(ObjectUtils.isEmpty(daysCom)){
            Result result = RestTemplateUtils.get(CommonUrlConstants.ADMIN_HOST+"/sysCommonBase/value/"+CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS,null,restTemplate);
            if(result.getCode() == CommonConstants.SUCCESS && !ObjectUtils.isEmpty(result.getData())){
                daysCom = (String)result.getData();
                redisService.set(CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS,daysCom);
                returnDays = Integer.valueOf(daysCom);
            }else{
                SendUtils.dingMsgNotLog("getDaysCommonBaseSetForVip获取基础配置days异常请排查",DateUtil.getCurrTime()+" 当前设置默认值价格房态查询5天 result="+GsonUtils.GsonString(result), MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
                returnDays = 5;//有异常默认5天并推送钉钉
            }
        }else{
            returnDays = Integer.valueOf(daysCom);
        }

        return returnDays;
    }
    /**
     * 获取普通酒店天数
     * @return
     */
    public Integer getDaysCommonBaseSetForNormal() {
        Integer returnDays;
        String daysCom = (String)redisService.get(CallbackConstants.SWMT_NORMAL_HOTELS_PRICE_STATUS_DAYS);
        if(ObjectUtils.isEmpty(daysCom)){
            Result result = RestTemplateUtils.get(CommonUrlConstants.ADMIN_HOST+"/sysCommonBase/value/"+CallbackConstants.SWMT_NORMAL_HOTELS_PRICE_STATUS_DAYS,null,restTemplate);
            if(result.getCode() == CommonConstants.SUCCESS && !ObjectUtils.isEmpty(result.getData())){
                daysCom = (String)result.getData();
                redisService.set(CallbackConstants.SWMT_NORMAL_HOTELS_PRICE_STATUS_DAYS,daysCom);
                returnDays = Integer.valueOf(daysCom);
            }else{
                SendUtils.dingMsgNotLog("getDaysCommonBaseSetForNormal获取基础配置days异常请排查",DateUtil.getCurrTime()+" 当前设置默认值价格房态查询3天 result="+GsonUtils.GsonString(result), MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
                returnDays = 3;//有异常默认3天并推送钉钉
            }
        }else{
            returnDays = Integer.valueOf(daysCom);
        }
        return returnDays;
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/17
     * 推送取消规则
     */
    private List<RoomDataEntityVo> roomDataEntityVoCancel(SwitchCreateRoomEntity switchCreateRoomEntity, List<MtHotelGoodsCancelRuleReturnVo> mtHotelGoodsCancelRuleReturnVos) {
        log.info("==============创建推送取消实体=======================");
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        //遍历美团的取消规则
        RoomDataEntityVo roomDataEntityVo;
        RoomDataEntityVo qunarRoomDataEntityVo;
        RoomDataEntityVo b2bRoomDataEntityVo;
        //渠道名称
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        String QunarChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
        String b2bChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
        //遍历取消规则
        for(MtHotelGoodsCancelRuleReturnVo mtHotelGoodsCancelRuleReturnVo:mtHotelGoodsCancelRuleReturnVos){
            roomDataEntityVo=new RoomDataEntityVo();
            roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            roomDataEntityVo.setStartDate(mtHotelGoodsCancelRuleReturnVo.getDate());
            roomDataEntityVo.setEndDate(mtHotelGoodsCancelRuleReturnVo.getDate());
            qunarRoomDataEntityVo=new RoomDataEntityVo();
            qunarRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            qunarRoomDataEntityVo.setStartDate(mtHotelGoodsCancelRuleReturnVo.getDate());
            qunarRoomDataEntityVo.setEndDate(mtHotelGoodsCancelRuleReturnVo.getDate());
            b2bRoomDataEntityVo=new RoomDataEntityVo();
            b2bRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            b2bRoomDataEntityVo.setStartDate(mtHotelGoodsCancelRuleReturnVo.getDate());
            b2bRoomDataEntityVo.setEndDate(mtHotelGoodsCancelRuleReturnVo.getDate());
            SaleRuleModelVo saleRuleModelVo=new SaleRuleModelVo();
            //携程
            CtripSellRuleVo ctripSellRuleVo=new CtripSellRuleVo();
            //不可取消
            if(mtHotelGoodsCancelRuleReturnVo.getCancelType()==0){
                ctripSellRuleVo.setCancelType(1);
                ctripSellRuleVo.setOverduePaymentType("F");
                saleRuleModelVo.setCtripSellRule(ctripSellRuleVo);
                saleRuleModelVo.setChannel(QunarChannel);
                qunarRoomDataEntityVo.setSaleRuleModel(saleRuleModelVo);
                saleRuleModelVo.setChannel(b2bChannel);
                b2bRoomDataEntityVo.setSaleRuleModel(saleRuleModelVo);
                roomDataEntityVos.add(qunarRoomDataEntityVo);
                roomDataEntityVos.add(b2bRoomDataEntityVo);
            }else{//可以取消
                ctripSellRuleVo.setCancelType(2);
                //提前取消时间类型 0 时间  1 时间量
                if(mtHotelGoodsCancelRuleReturnVo.getDeductType()==0){
                    ctripSellRuleVo.setLatestCancelTimeOfDays(mtHotelGoodsCancelRuleReturnVo.getAheadCancelDays());
                    ctripSellRuleVo.setLatestCancelTimeOfHours(Integer.parseInt(Arrays.stream(mtHotelGoodsCancelRuleReturnVo.getAheadCancelHours().split(":")).findFirst().get()));
                    ctripSellRuleVo.setOverduePaymentType("F");
                }else{
                    ctripSellRuleVo.setLatestCancelTimeOfDays(mtHotelGoodsCancelRuleReturnVo.getAheadCancelDays());
                    int hours=Integer.parseInt(mtHotelGoodsCancelRuleReturnVo.getAheadCancelHours());
                    ctripSellRuleVo.setLatestCancelTimeOfHours(24-hours);
                    ctripSellRuleVo.setOverduePaymentType("F");
                }
            }
            saleRuleModelVo.setCtripSellRule(ctripSellRuleVo);
            saleRuleModelVo.setChannel(channel);
            roomDataEntityVo.setSaleRuleModel(saleRuleModelVo);
            roomDataEntityVos.add(roomDataEntityVo);
        }


        return roomDataEntityVos;
    }


    /**
     * 重新推送房态房量
     */
    @Override
    public Result<Object> retryPushRoomData(int hotelId, int basicRoomTypeId, int genre) {
        //1.获取对应的产品id
        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectGoods(hotelId, basicRoomTypeId);
        if (ObjectUtils.isEmpty(switchCreateRoomEntity)) {
            log.info("============找不到相应的创建售卖房型记录，请检查售卖房型id正确=======");
            return new Result<>("找不到相应的创建售卖房型记录，请检查售卖房型id正确");
        }
        int day=15;
        if(redisService.exists(CommonConstants.SWITCH_PUSH_DATA_DAY)){
            day= (int) redisService.get(CommonConstants.SWITCH_PUSH_DATA_DAY);
        }
        Map<String, Object> params = new HashMap<>();
        params.put("days", day);
        int mtGoodId = switchCreateRoomEntity.getMtGoodId();
        int mtHotelId = switchCreateRoomEntity.getMtHotelId();
        int mtRoomId = Integer.valueOf(switchCreateRoomEntity.getMtRoomId());
        //2.获取美团房价
        params.put("goodsId", mtGoodId);
        List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = getMtGoodsPrice(params);
        if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
            log.info("美团的产品价格日历数据为空");
            return new Result<>("美团的产品价格日历数据为空");
        }
        //3.获取美团的房态
        params.put("hotelId", mtHotelId);
        List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos = getMtGoodsStatus(params, mtGoodId);
        log.info("===============房态的数据长度为ss{}======", mtHotelGoodsStatusDetailStateVos.size());
        if (mtHotelGoodsStatusDetailStateVos.size() < 1) {
            mtHotelGoodsStatusDetailStateVos = new ArrayList<>();
        }
        BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
        batchPushRoomVo.setHotelId(hotelId);
        //5.封装房型推送数据实体
        List<RoomDataEntityVo> roomDataEntityVos = null;
        try {
            roomDataEntityVos = roomDataEntityVoV2(switchCreateRoomEntity, mtHotelGoodsPriceBaseDetailVos, mtHotelGoodsStatusDetailStateVos, "",null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (ObjectUtils.isEmpty(roomDataEntityVos) || roomDataEntityVos.size() < 1) {
            log.info("推送的实体数据为空");
            return new Result<>("推送的实体数据为空");
        }
        //对日期时间相同的价格进行合并
        /*   roomDataEntityVos=mergeRoomDataEntityVo(roomDataEntityVos);*/
        batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
        log.info("==============推送的房型数据实体为{}====================", roomDataEntityVos);
        return pushRoomDataNewNoSave(batchPushRoomVo);
    }


    /**
     * @author: lmf
     * @date: 2020/8/5 16:41
     * 调用携程的推送接口
     */
    public Result<Object> pushRoomDataNewNoSave(BatchPushRoomVo batchPushRoomVo) {
        if (batchPushRoomVo.getRoomDataEntitys().size() < 1) {
            return new Result<>("推送的实体数据为空");
        }
        log.info("==============日志记录size为{}", switchPushRoomDataEntities.size());
        //6.调用直连推送报价
        Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
        if (result.getCode() == CommonConstants.SUCCESS) {
            return new Result<>(result.getCode(), "=======推送数据实体成功========");
        } else {
            return new Result<>(result.getMsg());
        }
    }

    /**
     * @author: lmf
     * @date: 2020/8/5 16:41
     * 调用携程的推送接口
     */
    public Result<Object> pushRoom(BatchPushRoomVo batchPushRoomVo) {
        if (batchPushRoomVo.getRoomDataEntitys().size() < 1) {
            return new Result<>("推送的实体数据为空");
        }
        log.info("==============日志记录size为{}", switchPushRoomDataEntities.size());
        //6.调用直连推送报价
        Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
        //当前操作时间戳
        SimpleDateFormat ds = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String time = ds.format(date);
        SendUtils.dingMsg(time + "直连推送报价等数据接口酒店id" + batchPushRoomVo.getHotelId() + "售卖房型id" + batchPushRoomVo.getRoomDataEntitys().get(0).getRoomId(), "请求状态" + result.getMsg().toString(), 1, restTemplate);
        if (result.getCode() == CommonConstants.SUCCESS) {
            return new Result<>(result.getCode(), "=======推送数据实体成功========");
        } else {
            return new Result<>(result.getMsg());
        }
    }

    /**
     * @param switchPushRoomDataEntities SwitchPushRoomDataEntity 只有一条记录
     *                                   switchPushRoomDataLogEntities 一对多
     * @author: lmf
     * @date: 2020/8/7 18:01
     * 推送日志记录
     */
    private synchronized void addLogToPushLog(List<SwitchPushRoomDataAllEntity> switchPushRoomDataEntities) {
        if (ObjectUtils.isEmpty(switchPushRoomDataEntities) || switchPushRoomDataEntities.size() < 1) {
            log.info("==========推送记录为空,无法记录==========");
            return;
        }
        List<SwitchPushRoomDataLogEntity> switchPushRoomDataLogEntities = new ArrayList<>();
        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String endTime = sdf.format(dt);
        log.info("=================addLogToPushLog的roomId为{}", switchPushRoomDataEntities.get(0).getRoomId());
        String key = CommonConstants.SWITCH_AUTO_KEY + switchPushRoomDataEntities.get(0).getHotelId() + switchPushRoomDataEntities.get(0).getRoomId();
        //String logkey=CommonConstants.SWITCH_AUTO_KEY_LOG+switchPushRoomDataEntities.get(0).getHotelId()+switchPushRoomDataEntities.get(0).getRoomId();
        //推送记录
        SwitchPushRoomDataEntity switchPushRoomDataEntity;
        if (redisService.exists(key)) {
            switchPushRoomDataEntity = switchPushRoomDataMapper.selectByRoomId(switchPushRoomDataEntities.get(0).getRoomId());
            log.info("==============缓存存在推送记录{}===================", switchPushRoomDataEntity);
        } else {
            switchPushRoomDataEntity = switchPushRoomDataMapper.selectByRoomId(switchPushRoomDataEntities.get(0).getRoomId());
            if (!ObjectUtils.isEmpty(switchPushRoomDataEntity)) {
                redisService.set(key, switchPushRoomDataEntity, (long) 200);
                log.info("==============缓存不存在推送记录,新入缓存成功{}===================", switchPushRoomDataEntity);
            }
        }
        String pid = "";
        for (SwitchPushRoomDataAllEntity switchPushRoomDataAllEntity : switchPushRoomDataEntities) {
            if (ObjectUtils.isEmpty(switchPushRoomDataEntity)) {
                switchPushRoomDataEntity = new SwitchPushRoomDataEntity();
                try {
                    BeanUtils.copyProperties(switchPushRoomDataEntity, switchPushRoomDataAllEntity);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                pid = StringUtil.getUUID();
                switchPushRoomDataEntity.setId(pid);
                int size = switchPushRoomDataMapper.insert(switchPushRoomDataEntity);
                if (size > 0) {
                    log.info("==============缓存不存在推送记录,第一次新入缓存成功{}===================", switchPushRoomDataEntity);
                    redisService.set(key, switchPushRoomDataEntity, (long) 200);
                }
            } else {
                pid = switchPushRoomDataEntity.getId();
                //获取最晚的时间
                if (DateUtil.commpareDay(endTime, switchPushRoomDataAllEntity.getStartTime())) {
                    endTime = switchPushRoomDataAllEntity.getStartTime();
                }
            }
            SwitchPushRoomDataLogEntity switchPushRoomDataLogEntity = new SwitchPushRoomDataLogEntity();
            try {
                BeanUtils.copyProperties(switchPushRoomDataLogEntity, switchPushRoomDataAllEntity);
            } catch (Exception e) {
                e.printStackTrace();
            }
            String uniqueKey = pid + switchPushRoomDataAllEntity.getStartTime().replace("-", "");
            switchPushRoomDataLogEntity.setUniqueKey(uniqueKey);
            switchPushRoomDataLogEntity.setPid(pid);
            switchPushRoomDataLogEntity.setStartTime(switchPushRoomDataAllEntity.getStartTime());
            switchPushRoomDataLogEntity.setLastPrice(switchPushRoomDataLogEntity.getPrice());
            switchPushRoomDataLogEntity.setId(StringUtil.getUUID());
            switchPushRoomDataLogEntities.add(switchPushRoomDataLogEntity);
        }
        log.info("===================结束时间为{}===", endTime);
        if (DateUtil.commpareDay(switchPushRoomDataEntity.getStartTime(), endTime)) {
            switchPushRoomDataMapper.updateStartTimeById(endTime, pid);
        }
    }

    /**
     * 推送一个某酒店的所有房型 多线程操作
     *
     * @param hotelId
     * @param basicRoomTypeId
     * @return
     */
    @Override
    @Transactional
    public Result<Object> pushAllRoomData(int hotelId, int[] basicRoomTypeId) {
        List<Future<Result<Object>>> threads = new ArrayList<>();
        for (int i = 0; i < basicRoomTypeId.length; i++) {
            threads.add(executor.submit(new PushDataCallable("线程名称为thread" + i, hotelId, basicRoomTypeId[i])));
        }
        for (Future<Result<Object>> future : threads) {
            try {
                if (future.get().getCode() == CommonConstants.SUCCESS) {
                    log.info("====推送成功=======");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return new Result<>("推送房价数据成功");
    }

    /**
     * 使用内部类用来处理推送价格
     */
    class PushDataCallable implements Callable<Result<Object>> {
        String threadName;
        int hotelId;
        int roomId;

        public PushDataCallable(String threadName, int hotelId, int roomId) {
            this.threadName = threadName;
            this.hotelId = hotelId;
            this.roomId = roomId;
        }

        @Override
        public Result<Object> call() {
            return pushRoomData(hotelId, roomId, 0);
        }
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/15
     * 获取取消规则
     */
    private List<MtHotelGoodsCancelRuleReturnVo> getMtHotelGoodsCancelRuleReturn(Map<String, Object> params) {
        List<MtHotelGoodsCancelRuleReturnVo> mtHotelGoodsCancelRuleReturnVos = new ArrayList<>();
        String url = MEI_TUAN_URL + MtRequestUrlEnums.GET_CANCEL_BY_GOODS_INFO.getUrl();
        try {
            Result<List<MtHotelGoodsCancelRuleReturnVo>> result1 = switchRestTempaleUtilsService.sendPostRequestGetGoodsCancelRule(url, params);
            if (result1.getCode() == CommonConstants.SUCCESS) {
                mtHotelGoodsCancelRuleReturnVos = result1.getData();
                if (ObjectUtils.isEmpty(mtHotelGoodsCancelRuleReturnVos) || mtHotelGoodsCancelRuleReturnVos.size() < 1) {
                    log.info("=============美团的产品取消规则返回数据为空=====================");
                } else {
                    log.info("=============美团的产品取消规则成功，条数为{}", mtHotelGoodsCancelRuleReturnVos.size());
                }
            }
        } catch (Exception e) {
            log.info("=============获取产品取消规则发生的异常为{}============", e.getMessage());
            return new ArrayList<>();
        }
        return mtHotelGoodsCancelRuleReturnVos;
    }

    /**
     * 获取美团产品价格
     */
    public List<MtHotelGoodsPriceBaseDetailVo> getMtGoodsPrice(Map<String, Object> params) {
        List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = new ArrayList<>();
        String url = MEI_TUAN_URL + MtRequestUrlEnums.GET_MT_GOODS_PRICE_BY_HOTEL_ID.getUrl();
        try {
            Result<List<MtHotelGoodsPriceBaseDetailVo>> result1 = switchRestTempaleUtilsService.sendPostRequestGetGoodsPrice(url, params);
            if (result1.getCode() == CommonConstants.SUCCESS) {
                mtHotelGoodsPriceBaseDetailVos = result1.getData();
                if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
                    log.info("=============美团的产品价格日历返回数据为空=====================");
                } else {
                    log.info("=============美团的产品价格日历返回数据成功，条数为{}", mtHotelGoodsPriceBaseDetailVos.size());
                }
            }
        } catch (Exception e) {
            log.info("=============获取产品价格日历发生的异常为{}============", e.getMessage());
            return new ArrayList<>();
        }
        return mtHotelGoodsPriceBaseDetailVos;
    }

    /**
     * 获取美团房态
     */
    public List<MtHotelGoodsStatusDetailStateVo> getMtGoodsStatus(Map<String, Object> params, int mtGoodId) {
        String url = MEI_TUAN_URL + MtRequestUrlEnums.GET_MT_GOODS_STATUS_BY_DAYS.getUrl();
        List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos = new ArrayList<>();
        try {
            Result<Map<Integer, List<MtHotelGoodsStatusDetailStateVo>>> result2 = switchRestTempaleUtilsService.sendPostRequestGetGoodsStatus(url, params);
            if (result2.getCode() == CommonConstants.SUCCESS) {
                Map<Integer, List<MtHotelGoodsStatusDetailStateVo>> map = result2.getData();
                if (ObjectUtils.isEmpty(map)) {
                    log.info("=============美团的产品房态返回数据为空=====================");
                } else {
                    //产品房态
                    if (map.containsKey(mtGoodId)) {
                        mtHotelGoodsStatusDetailStateVos = map.get(mtGoodId);
                        log.info("==========产品房态===========，条数为{}", mtHotelGoodsStatusDetailStateVos.size());
                    }
                }
            } else {
                log.info("=======房态返回失败=========,失败原因是{}", result2.getMsg());
            }
        } catch (Exception e) {
            log.info("========获取美团房态发生的异常为{}==================", e.getMessage());
            return mtHotelGoodsStatusDetailStateVos;
        }
        return mtHotelGoodsStatusDetailStateVos;
    }

    /**
     * 获取美团的库存
     */
    public MtHotelGoodsInventoryVo getMtGoodsInventory(Map<String, Object> params) {
        MtHotelGoodsInventoryVo mtHotelGoodsInventoryVo = new MtHotelGoodsInventoryVo();
        String url = MEI_TUAN_URL + MtRequestUrlEnums.GET_MT_GOODS_INVENTORY_BY_DAYS.getUrl();
        try {
            Result<MtHotelGoodsInventoryVo> result2 = switchRestTempaleUtilsService.sendPostRequestGetGoodsInventory(url, params);
            if (ObjectUtils.isEmpty(result2)) {
                log.info("===============token实效========================");
                return null;
            }
            log.info("============返回的数据为{}", result2);
            if (result2.getCode() == CommonConstants.SUCCESS) {
                mtHotelGoodsInventoryVo = result2.getData();
                log.info("库存返回成功,返回的数据是{}", mtHotelGoodsInventoryVo);
            } else {
                log.info("=======库存返回失败=========,失败原因是{}", result2.getMsg());
            }
        } catch (Exception e) {
            log.info("==========获取美团的库存发生的异常为{}=============", e.getMessage());
            return null;
        }
        return mtHotelGoodsInventoryVo;
    }

    /**
     * 获取上架配置
     * 比如哪些酒店 哪些星级 可以进行售卖，前期控制
     * 上架规则:
     * 1.按照省+星级来上架
     * 2.按照市+星级来上架
     * 3.按照制定id来上架
     * 4.根据渠道来
     */
    public SwitchRoomPriceSetEntity getOnlineSet(int masterId, String channel) {
        //判断酒店是否是设置的范围内，比如是否满足城市 地区
        SwitchRoomPriceSetEntity switchRoomPriceSetEntity = new SwitchRoomPriceSetEntity();
        //获取总配置表
        String key = CommonConstants.SWITCH_BASE_SET_KEY;
        SwitchBaseSetEntity switchBaseSetEntity = new SwitchBaseSetEntity();
        if (redisService.exists(key)) {
            switchBaseSetEntity = (SwitchBaseSetEntity) redisService.get(key);
        } else {
            switchBaseSetEntity.setId(1);
            switchBaseSetEntity = switchBaseSetMapper.selectOne(switchBaseSetEntity);
            redisService.set(key, switchBaseSetEntity, (long) 20000);
        }
        int mold = switchBaseSetEntity.getMold();
        SwitchMasterHotelInfoDto switchMasterHotelInfoDto;
        switch (mold) {
            case 0:
                if (!redisService.exists(String.valueOf(masterId))) {
                    switchMasterHotelInfoDto = switchMasterHotelInfoMapper.selectByMasterHotelId(masterId);
                    redisService.set(String.valueOf(masterId), switchMasterHotelInfoDto, (long) 10000);
                } else {
                    switchMasterHotelInfoDto = (SwitchMasterHotelInfoDto) redisService.get(String.valueOf(masterId));
                }
                if (ObjectUtils.isEmpty(switchMasterHotelInfoDto)) {
                    log.info("=====查询不到酒店信息=====");
                    return switchRoomPriceSetEntity;
                }
                switchRoomPriceSetEntity = switchRoomPriceSetService.selectByStarAndTime(switchMasterHotelInfoDto.getHotelStar());
                break;
            case 1:
                if (redisService.exists(String.valueOf(masterId))) {
                    switchMasterHotelInfoDto = switchMasterHotelInfoMapper.selectByMasterHotelId(masterId);
                    redisService.set(String.valueOf(masterId), switchMasterHotelInfoDto, (long) 10000);
                } else {
                    switchMasterHotelInfoDto = (SwitchMasterHotelInfoDto) redisService.get(String.valueOf(masterId));
                }
                if (ObjectUtils.isEmpty(switchMasterHotelInfoDto)) {
                    log.info("=====查询不到酒店信息=====");
                    return switchRoomPriceSetEntity;
                }
                switchRoomPriceSetEntity = switchRoomPriceSetService.selectByCityNameAndTime(switchMasterHotelInfoDto.getCityName());
                break;
            case 2:
                if (redisService.exists(String.valueOf(masterId))) {
                    switchMasterHotelInfoDto = switchMasterHotelInfoMapper.selectByMasterHotelId(masterId);
                    redisService.set(String.valueOf(masterId), masterHotelInfoDtoMap, (long) 10000);
                } else {
                    switchMasterHotelInfoDto = (SwitchMasterHotelInfoDto) redisService.get(String.valueOf(masterId));
                }
                if (ObjectUtils.isEmpty(switchMasterHotelInfoDto)) {
                    log.info("=====查询不到酒店信息=====");
                    return switchRoomPriceSetEntity;
                }
                switchRoomPriceSetEntity = switchRoomPriceSetService.selectByCityNameAndStarAndTime(switchMasterHotelInfoDto.getCityName(), switchMasterHotelInfoDto.getHotelStar());
                break;
            default:
                if (ObjectUtils.isEmpty(channel)) {//没有传入渠道
                    String keys = CommonConstants.SWITCH_ROOM_PRICE_SET;
                    if (redisService.exists(keys)) {
                        switchRoomPriceSetEntity = (SwitchRoomPriceSetEntity) redisService.get(keys);
                    } else {
                        switchRoomPriceSetEntity = switchRoomPriceSetService.selectByTime();
                        redisService.set(keys, switchRoomPriceSetEntity, (long) 20000);
                    }
                } else {//有传入渠道,就根据渠道获取配置
                    String keys = CommonConstants.SWITCH_ROOM_PRICE_SET + "channel";
                    if (redisService.exists(keys)) {
                        switchRoomPriceSetEntity = (SwitchRoomPriceSetEntity) redisService.get(keys);
                    } else {
                        switchRoomPriceSetEntity = switchRoomPriceSetService.selectByChannel(channel);
                        if (!ObjectUtils.isEmpty(switchRoomPriceSetEntity)) {
                            redisService.set(keys, switchRoomPriceSetEntity, (long) 20000);
                        }
                    }
                }
                break;
        }
        return switchRoomPriceSetEntity;
    }

    /**
     * 获取酒店上架价格配置
     */
    public Map<String, List<SwitchPriceBaseSetEntity>> getOnlinePriceSet(){
        int day=0;
        if(redisService.exists(CommonConstants.SWITCH_PRICE_SET_PRICE_TIME)){
            Integer time= (Integer) redisService.get(CommonConstants.SWITCH_PRICE_SET_PRICE_TIME);
            Calendar calendar=Calendar.getInstance();
            int hour=calendar.get(Calendar.HOUR_OF_DAY);
            if(hour>=time){
                day=1;
            }
        }
        Map<String, List<SwitchPriceBaseSetEntity>> map=new HashMap<>();
        String key="switch_online_price_sets_up_by_"+ SwitchChannelNameEnums.CTRIP.getName();
        String qunarKey="switch_online_price_sets_up_by_"+SwitchChannelNameEnums.QUNAR.getName();
        List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntityByCtripChannel;
        if(redisService.exists(key)){
            log.info("======走缓存获取ctrip上架价格配置==================");
            String str= (String) redisService.get(key);
            switchPriceBaseSetEntityByCtripChannel=JacksonUtil.jsonToList(str,SwitchPriceBaseSetEntity.class);
            log.info("======走缓存获取ctrip上架价格配置，switchPriceBaseSetEntityByCtripChannel的值为{}==================",JacksonUtil.objectToJson(switchPriceBaseSetEntityByCtripChannel));
        }else{
            log.info("======走数据库获取ctrip上架价格配置==================");
            switchPriceBaseSetEntityByCtripChannel=switchPriceBaseSetMapper.selectByChannelNameAndDay(SwitchChannelNameEnums.CTRIP.getName(),day);
            redisService.set(key,JacksonUtil.objectToJson(switchPriceBaseSetEntityByCtripChannel),(long)20000);
        }
        List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntityByQunarChannel;
        if(redisService.exists(qunarKey)){
            String str= (String) redisService.get(qunarKey);
            switchPriceBaseSetEntityByQunarChannel=JacksonUtil.jsonToList(str,SwitchPriceBaseSetEntity.class);
            log.info("======走缓存获取qunar上架价格配置,switchPriceBaseSetEntityByQunarChannel的值为{}==================",JacksonUtil.objectToJson(switchPriceBaseSetEntityByQunarChannel));
        }else{
            log.info("======走数据库获取qunar上架价格配置==================");
            switchPriceBaseSetEntityByQunarChannel=switchPriceBaseSetMapper.selectByChannelNameAndDay(SwitchChannelNameEnums.QUNAR.getName(),day);
            redisService.set(qunarKey,JacksonUtil.objectToJson(switchPriceBaseSetEntityByQunarChannel),(long)20000);
        }
        map.put(SwitchChannelNameEnums.CTRIP.getName(),switchPriceBaseSetEntityByCtripChannel);
        map.put(SwitchChannelNameEnums.QUNAR.getName(),switchPriceBaseSetEntityByQunarChannel);
        return map;
    }

    /**
     * 封装直连推送报价接口 一个月 version 1.0
     *
     * @param switchCreateRoomEntity           创建售卖房型数据
     * @param mtHotelGoodsPriceBaseDetailVos   美团的产品日历列表
     * @param mtHotelGoodsStatusDetailStateVos 美团的房态
     * @param mtHotelGoodsInventoryVo          美团的库存
     * @param mtGoodId                         美团产品id
     * @param mtHotelId                        美团酒店id
     * @param mtRoomId                         美团房型id
     * @return
     */
    public List<RoomDataEntityVo> roomDataEntityVo(SwitchCreateRoomEntity switchCreateRoomEntity, List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos, List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos, MtHotelGoodsInventoryVo mtHotelGoodsInventoryVo, int mtGoodId, int mtHotelId, int mtRoomId, int first) throws InvocationTargetException, IllegalAccessException {
        log.info("=================开始获取配置===================");
        SwitchRoomPriceSetEntity switchRoomPriceSetEntity = getOnlineSet(switchCreateRoomEntity.getMasterHotelId(), null);
        SwitchRoomPriceSetEntity switchRoomPriceSetEntityByChannel = getOnlineSet(switchCreateRoomEntity.getMasterHotelId(), SwitchChannelNameEnums.CTRIP.getName());
        if (ObjectUtils.isEmpty(switchRoomPriceSetEntity)) {
            log.info("============该酒店不符合上架的设置规则===============================");
            return new ArrayList<>();
        }
        //如果渠道获取不到对应的配置，就直接用统一的配置
        if (ObjectUtils.isEmpty(switchRoomPriceSetEntityByChannel)) {
            switchRoomPriceSetEntityByChannel = switchRoomPriceSetEntity;
        }
        log.info("=============获取配置信息为{}=======", switchRoomPriceSetEntity.toString());
        log.info("================获取售卖房型的取消规则start===========");
        boolean isCanCancel = false;
        SwitchSetRoomSaleRuleEntity switchSetRoomSaleRuleEntity = switchSetRoomSaleRuleMapper.selectRuleByRoomId(switchCreateRoomEntity.getRoomId());
        if (!ObjectUtils.isEmpty(switchSetRoomSaleRuleEntity) && ObjectUtils.isEmpty(switchSetRoomSaleRuleEntity.getSaleRuleListJson())) {
            List<SaleRuleVo> saleRuleVos = JacksonUtil.jsonToList(switchSetRoomSaleRuleEntity.getSaleRuleListJson(), SaleRuleVo.class);
            if (!ObjectUtils.isEmpty(saleRuleVos) && saleRuleVos.size() < 1) {
                log.info("============获取售卖房型的售卖规则为空======");
                SaleRuleVo saleRuleVo = saleRuleVos.get(0);
                isCanCancel = saleRuleVo.isCanCancel();
            }
            log.info("================获取售卖房型的取消规则end=-======");
            log.info("=================该售卖房型的取消规则为{}", isCanCancel);
        }
        log.info("==============创建推送价格实体=======================");
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        //遍历美团价格
        for (MtHotelGoodsPriceBaseDetailVo mtHotelGoodsPriceBaseDetailVo : mtHotelGoodsPriceBaseDetailVos) {
            //用来标记是否有同一天
            boolean isSimilar = false;
            //推送价格记录表
            SwitchPushRoomDataAllEntity switchPushRoomDataEntity = new SwitchPushRoomDataAllEntity();
            //携程
            RoomDataEntityVo roomDataEntityVo = new RoomDataEntityVo();
            roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //去哪儿
            RoomDataEntityVo qunarRoomDataEntityVo = new RoomDataEntityVo();
            qunarRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //B2B
            RoomDataEntityVo b2bRoomDataEntityVo = new RoomDataEntityVo();
            b2bRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //channelA
            RoomDataEntityVo channelaRoomDataEntityVo = new RoomDataEntityVo();
            channelaRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //针对统一的进行价格公式计算
            Map<String, String> map = new HashMap<>();
            //针对特殊的渠道进行公式计算
            Map<String, String> mapByChannel = new HashMap<>();
            //判断是否参加促销活动
            SwitchHotelActiveTagEntity switchHotelActiveTagEntity = switchHotelActiveTagMapper.selectHotelIdAndRoomIdAndTime(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(), mtHotelGoodsPriceBaseDetailVo.getDate());
            if (ObjectUtils.isEmpty(switchHotelActiveTagEntity)) {
                log.info("============该房型在{}没有参与促销活动========", mtHotelGoodsPriceBaseDetailVo.getDate());
                //180以上按照美团的原价
                if (mtHotelGoodsPriceBaseDetailVo.getSalePrice() >= 18000) {
                    //  map=getOldPrice(switchRoomPriceSetEntity,mtHotelGoodsPriceBaseDetailVo.getSalePrice(),0,0,0);
                    map.put("rate", "0");
                    map.put("add_price", "0");
                    map.put("price", String.valueOf(mtHotelGoodsPriceBaseDetailVo.getSalePrice().doubleValue() / 100));
                    mapByChannel.putAll(map);
                } else {
                    map = getPrice(switchRoomPriceSetEntity, mtHotelGoodsPriceBaseDetailVo.getSalePrice() - mtHotelGoodsPriceBaseDetailVo.getSubPrice(), 0, 0, 0);
                    mapByChannel = getPrice(switchRoomPriceSetEntityByChannel, mtHotelGoodsPriceBaseDetailVo.getSalePrice() - mtHotelGoodsPriceBaseDetailVo.getSubPrice(), 0, 0, 0);
                }
            } else {
                String currentWeekDay = DateUtil.dayForWeek(mtHotelGoodsPriceBaseDetailVo.getDate());
                //促销
                if (switchHotelActiveTagEntity.getWeek().contains("每天") || switchHotelActiveTagEntity.getWeek().contains(currentWeekDay)) {
                    if (mtHotelGoodsPriceBaseDetailVo.getSalePrice() >= 18000) {
                        map = getOldLabelPrice(switchHotelActiveTagEntity, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), 0, 0, 0);
                        mapByChannel.putAll(map);
                    } else {
                        map = getLabelPrice(switchRoomPriceSetEntity, switchHotelActiveTagEntity, mtHotelGoodsPriceBaseDetailVo.getSalePrice() - mtHotelGoodsPriceBaseDetailVo.getSubPrice(), 0, 0, 0);
                        mapByChannel = getLabelPrice(switchRoomPriceSetEntityByChannel, switchHotelActiveTagEntity, mtHotelGoodsPriceBaseDetailVo.getSalePrice() - mtHotelGoodsPriceBaseDetailVo.getSubPrice(), 0, 0, 0);
                    }
                } else {//判断当前周几，是否符合促销活动
                    //超过180按照美团的原价
                    if (mtHotelGoodsPriceBaseDetailVo.getSalePrice() >= 18000) {
                        map.put("rate", "0");
                        map.put("add_price", "0");
                        map.put("price", String.valueOf(mtHotelGoodsPriceBaseDetailVo.getSalePrice().doubleValue() / 100));
                        mapByChannel.putAll(map);
                    } else {
                        map = getPrice(switchRoomPriceSetEntity, mtHotelGoodsPriceBaseDetailVo.getSalePrice() - mtHotelGoodsPriceBaseDetailVo.getSubPrice(), 0, 0, 0);
                        mapByChannel = getPrice(switchRoomPriceSetEntityByChannel, mtHotelGoodsPriceBaseDetailVo.getSalePrice() - mtHotelGoodsPriceBaseDetailVo.getSubPrice(), 0, 0, 0);
                    }
                    // map=getPrice(switchRoomPriceSetEntity,mtHotelGoodsPriceBaseDetailVo.getSalePrice()-mtHotelGoodsPriceBaseDetailVo.getSubPrice(),0,0,0);
                }
            }
            //如果价格符合公式，房态可预定 有库存就进行设置推送
            float price = Float.parseFloat(map.get("price"));
            float channelPrice = Float.parseFloat(mapByChannel.get("price"));
            //推送记录添加价格字段
            switchPushRoomDataEntity.setHotelId(switchCreateRoomEntity.getHotelId());
            switchPushRoomDataEntity.setMasterHotelId(switchCreateRoomEntity.getMasterHotelId());
            switchPushRoomDataEntity.setRoomId(switchCreateRoomEntity.getRoomId());
            switchPushRoomDataEntity.setMtHotelId(mtHotelId);
            switchPushRoomDataEntity.setMtGoodId(mtGoodId);
            switchPushRoomDataEntity.setPrice((double) price);
            switchPushRoomDataEntity.setRate(Double.valueOf(map.get("rate")));
            switchPushRoomDataEntity.setAddPrice(Double.valueOf(map.get("add_price")));
            switchPushRoomDataEntity.setPriceRate(price + price * 0.12);
            switchPushRoomDataEntity.setMtPrice((double) (mtHotelGoodsPriceBaseDetailVo.getSalePrice() / 100));
            switchPushRoomDataEntity.setMtSubPrice((double) (mtHotelGoodsPriceBaseDetailVo.getSubPrice() / 100));
            switchPushRoomDataEntity.setStatus(0);
            switchPushRoomDataEntity.setRemark("");
            switchPushRoomDataEntity.setMtRoomId(mtRoomId);
            switchPushRoomDataEntity.setStartTime(mtHotelGoodsPriceBaseDetailVo.getDate());
            switchPushRoomDataEntity.setEndTime(mtHotelGoodsPriceBaseDetailVo.getDate());
            //房价推送实体
            //携程
            roomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            roomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //去哪儿
            qunarRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            qunarRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //b2b
            b2bRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            b2bRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //channelA
            channelaRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            channelaRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //携程房价实体
            RoomPriceModelVo roomPriceModelVo = new RoomPriceModelVo();
            roomPriceModelVo.setRoomPrice(channelPrice);
            roomPriceModelVo.setCurrency("CNY");
            //去哪儿房价实体
            RoomPriceModelVo qunarroomPriceModelVo = new RoomPriceModelVo();
            qunarroomPriceModelVo.setRoomPrice(price);
            qunarroomPriceModelVo.setCurrency("CNY");
            //b2b房价实体
            RoomPriceModelVo b2broomPriceModelVo = new RoomPriceModelVo();
            //channel房价实体
            RoomPriceModelVo channelroomPriceModelVo = new RoomPriceModelVo();
            //渠道名称
            String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
            String QunarChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
            String b2bChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
            String channelChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_CHANNEL_A.getName());
            //BeanUtils.copyProperties(qunarroomPriceModelVo,roomPriceModelVo);
            BeanUtils.copyProperties(b2broomPriceModelVo, qunarroomPriceModelVo);
            BeanUtils.copyProperties(channelroomPriceModelVo, qunarroomPriceModelVo);
            //携程
            roomPriceModelVo.setChannel(channel);
            roomDataEntityVo.setRoomPriceModel(roomPriceModelVo);
            //去哪儿
            qunarroomPriceModelVo.setChannel(QunarChannel);
            qunarRoomDataEntityVo.setRoomPriceModel(qunarroomPriceModelVo);
            //b2b
            b2broomPriceModelVo.setChannel(b2bChannel);
            b2bRoomDataEntityVo.setRoomPriceModel(b2broomPriceModelVo);
            //channelA
            channelroomPriceModelVo.setChannel(channelChannel);
            channelaRoomDataEntityVo.setRoomPriceModel(channelroomPriceModelVo);
            if (mtHotelGoodsStatusDetailStateVos.size() < 1) {
                //房态推送实体
                //携程房态实体
                RoomStatusModelVo roomStatusModelVo = new RoomStatusModelVo();
                //去哪儿房态实体
                RoomStatusModelVo qunarRoomStatusModelVo = new RoomStatusModelVo();
                //b2b房态实体
                RoomStatusModelVo b2bRoomStatusModelVo = new RoomStatusModelVo();
                //channel房态实体
                RoomStatusModelVo channelRoomStatusModelVo = new RoomStatusModelVo();
                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                switchPushRoomDataEntity.setSale(0);
                roomStatusModelVo.setChannel(channel);
                roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                //去哪儿实体
                BeanUtils.copyProperties(qunarRoomStatusModelVo, roomStatusModelVo);
                qunarRoomStatusModelVo.setChannel(QunarChannel);
                qunarRoomDataEntityVo.setRoomStatusModel(qunarRoomStatusModelVo);
                //b2b实体
                BeanUtils.copyProperties(b2bRoomStatusModelVo, roomStatusModelVo);
                b2bRoomStatusModelVo.setChannel(b2bChannel);
                b2bRoomDataEntityVo.setRoomStatusModel(b2bRoomStatusModelVo);
                //channel实体
                BeanUtils.copyProperties(channelRoomStatusModelVo, roomStatusModelVo);
                channelRoomStatusModelVo.setChannel(channelChannel);
                channelaRoomDataEntityVo.setRoomStatusModel(channelRoomStatusModelVo);
                //库存推送实体
                RoomInventoryModelVo roomInventoryModelVo = new RoomInventoryModelVo();
                //可以取消设置为保留房 不可以取消设置为非保留房
                isCanCancel = false;
                if (isCanCancel) {
                    roomInventoryModelVo.setPreservedQuantity(1);
                    roomInventoryModelVo.setUnPreservedQuantity(0);
                } else {
                    roomInventoryModelVo.setPreservedQuantity(0);
                    roomInventoryModelVo.setUnPreservedQuantity(1);
                }
                if (first > 0) {
                    roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.ADD.getCode());
                    roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.ADD.getCode());
                } else {
                    roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                    roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                }
                roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                roomInventoryModelVo.setChannel(QunarChannel);
                qunarRoomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                roomDataEntityVos.add(b2bRoomDataEntityVo);
                roomDataEntityVos.add(channelaRoomDataEntityVo);
                roomDataEntityVos.add(roomDataEntityVo);
                roomDataEntityVos.add(qunarRoomDataEntityVo);
            } else {
                //遍历房态
                for (MtHotelGoodsStatusDetailStateVo mtHotelGoodsStatusDetailStateVo : mtHotelGoodsStatusDetailStateVos) {
                    //匹配同一天日期
                    if (mtHotelGoodsPriceBaseDetailVo.getDate().equals(mtHotelGoodsStatusDetailStateVo.getDate())) {
                        log.info("===========有相同的日期=============");
                        isSimilar = true;
                        //房态推送实体
                        RoomStatusModelVo roomStatusModelVo = new RoomStatusModelVo();
                        //去哪儿房态实体
                        RoomStatusModelVo qunarRoomStatusModelVo = new RoomStatusModelVo();
                        //b2b房态实体
                        RoomStatusModelVo b2bRoomStatusModelVo = new RoomStatusModelVo();
                        //channel房态实体
                        RoomStatusModelVo channelRoomStatusModelVo = new RoomStatusModelVo();
                        if (mtHotelGoodsInventoryVo.getRemain() > 0) {
                            switchPushRoomDataEntity.setSale(1);
                            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                        } else {
                            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                            switchPushRoomDataEntity.setSale(0);
                        }
                        if (mtHotelGoodsStatusDetailStateVo.getStatus() == 1) {
                            switchPushRoomDataEntity.setSale(1);
                            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                        } else {
                            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                            switchPushRoomDataEntity.setSale(0);
                        }
                        roomStatusModelVo.setChannel(channel);
                        roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                        //去哪儿房态设置
                        BeanUtils.copyProperties(qunarRoomStatusModelVo, roomStatusModelVo);
                        qunarRoomStatusModelVo.setChannel(QunarChannel);
                        qunarRoomDataEntityVo.setRoomStatusModel(qunarRoomStatusModelVo);
                        //b2b房态实体设置
                        BeanUtils.copyProperties(b2bRoomStatusModelVo, roomStatusModelVo);
                        b2bRoomStatusModelVo.setChannel(b2bChannel);
                        b2bRoomDataEntityVo.setRoomStatusModel(qunarRoomStatusModelVo);
                        //channel房态实体设置
                        BeanUtils.copyProperties(channelRoomStatusModelVo, roomStatusModelVo);
                        channelRoomStatusModelVo.setChannel(channelChannel);
                        channelaRoomDataEntityVo.setRoomStatusModel(channelRoomStatusModelVo);
                        //房量推送实体
                        RoomInventoryModelVo roomInventoryModelVo = new RoomInventoryModelVo();
                        RoomInventoryModelVo qunarRoomInventoryModelVo = new RoomInventoryModelVo();
                        //可以取消设置为保留房 不可以取消设置为非保留房
                        isCanCancel = false;
                        if (isCanCancel) {
                            roomInventoryModelVo.setPreservedQuantity(1);
                            roomInventoryModelVo.setUnPreservedQuantity(0);
                        } else {
                            roomInventoryModelVo.setPreservedQuantity(0);
                            roomInventoryModelVo.setUnPreservedQuantity(1);
                        }
                        if (first > 0) {
                            roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.ADD.getCode());
                            roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.ADD.getCode());
                        } else {
                            roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                            roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                        }
                        roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                        roomInventoryModelVo.setChannel(channel);
                        roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                        //去哪儿
                        BeanUtils.copyProperties(qunarRoomInventoryModelVo, roomInventoryModelVo);
                        roomDataEntityVos.add(roomDataEntityVo);
                        roomDataEntityVos.add(qunarRoomDataEntityVo);
                        roomDataEntityVos.add(b2bRoomDataEntityVo);
                        roomDataEntityVos.add(channelaRoomDataEntityVo);
                    }
                }
            }
            if (!isSimilar) {
                log.info("================无相同的日期,日期为{}", mtHotelGoodsPriceBaseDetailVo.getDate());
                //房态推送实体
                RoomStatusModelVo roomStatusModelVo = new RoomStatusModelVo();
                RoomStatusModelVo qunarRoomStatusModelVo = new RoomStatusModelVo();
                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                roomStatusModelVo.setChannel(channel);
                roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                BeanUtils.copyProperties(qunarRoomStatusModelVo, roomStatusModelVo);
                qunarRoomStatusModelVo.setChannel(QunarChannel);
                qunarRoomDataEntityVo.setRoomStatusModel(qunarRoomStatusModelVo);
                //房量推送实体
                RoomInventoryModelVo roomInventoryModelVo = new RoomInventoryModelVo();
                RoomInventoryModelVo qunarRoomInventoryModelVo = new RoomInventoryModelVo();
                //可以取消设置为保留房 不可以取消设置为非保留房
                if (isCanCancel) {
                    roomInventoryModelVo.setPreservedQuantity(1);
                    roomInventoryModelVo.setUnPreservedQuantity(0);
                } else {
                    roomInventoryModelVo.setPreservedQuantity(0);
                    roomInventoryModelVo.setUnPreservedQuantity(1);
                }
                if (first > 0) {
                    roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.ADD.getCode());
                    roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.ADD.getCode());
                } else {
                    roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                    roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                }
                roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                roomInventoryModelVo.setChannel(channel);
                roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                BeanUtils.copyProperties(qunarRoomInventoryModelVo, roomInventoryModelVo);
                roomDataEntityVos.add(roomDataEntityVo);
                roomDataEntityVos.add(qunarRoomDataEntityVo);
            }
            isSimilar = false;
            //推送价格记录表 保存房型推送数据实体数据
            List<RoomDataEntityVo> roomDataEntityVo_temp = new ArrayList<>();
            roomDataEntityVo_temp.add(roomDataEntityVo);
            roomDataEntityVo_temp.add(qunarRoomDataEntityVo);
            roomDataEntityVo_temp.add(b2bRoomDataEntityVo);
            roomDataEntityVo_temp.add(channelaRoomDataEntityVo);
            switchPushRoomDataEntity.setFormData(JSONArray.fromObject(roomDataEntityVo_temp).toString());
            switchPushRoomDataEntities.add(switchPushRoomDataEntity);
        }
        return roomDataEntityVos;
    }

    /**
     * 封装直连推送报价接口 一个月 2020-09-11日开发
     * @param switchCreateRoomEntity           创建售卖房型数据
     * @param mtHotelGoodsPriceBaseDetailVos   美团的产品日历列表
     * @param mtHotelGoodsStatusDetailStateVos 美团的房态
     * @param mtHotelGoodsCancelRuleReturnVos  美团的取消规则列表
     * @return version v2 版本 2
     */
    public List<RoomDataEntityVo> roomDataEntityVoV2(SwitchCreateRoomEntity switchCreateRoomEntity, List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos, List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos, String time, List<MtHotelGoodsCancelRuleReturnVo> mtHotelGoodsCancelRuleReturnVos) throws InvocationTargetException, IllegalAccessException {
        log.info("=================获取酒店上架价格配置start===================");
        Map<String, List<SwitchPriceBaseSetEntity>> priceSetMap = getOnlinePriceSet();
        log.info("=================获取酒店上架价格配置end===================");
        log.info("================获取售卖房型的取消规则start===========");
        boolean isCanCancel = false;
        SwitchSetRoomSaleRuleEntity switchSetRoomSaleRuleEntity = switchSetRoomSaleRuleMapper.selectRuleByRoomId(switchCreateRoomEntity.getRoomId());
        if (!ObjectUtils.isEmpty(switchSetRoomSaleRuleEntity) && ObjectUtils.isEmpty(switchSetRoomSaleRuleEntity.getSaleRuleListJson())) {
            List<SaleRuleVo> saleRuleVos = JacksonUtil.jsonToList(switchSetRoomSaleRuleEntity.getSaleRuleListJson(), SaleRuleVo.class);
            if (!ObjectUtils.isEmpty(saleRuleVos) && saleRuleVos.size() < 1) {
                log.info("============获取售卖房型的售卖规则为空======");
                SaleRuleVo saleRuleVo = saleRuleVos.get(0);
                isCanCancel = saleRuleVo.isCanCancel();
            }
            log.info("================获取售卖房型的取消规则end=-======");
        }
        log.info("==============创建推送价格实体=======================");
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        //遍历美团价格
        RoomDataEntityVo roomDataEntityVo;
        RoomDataEntityVo qunarRoomDataEntityVo;
        RoomDataEntityVo b2bRoomDataEntityVo;
        RoomDataEntityVo channelaRoomDataEntityVo;
        Map<String, Object> map;
        double price=0.0;
        double channelPrice=0.0;
        SwitchHotelActiveTagEntity switchHotelActiveTagEntity;
        RoomPriceModelVo roomPriceModelVo;
        RoomPriceModelVo qunarroomPriceModelVo;
        RoomPriceModelVo b2broomPriceModelVo;
        RoomPriceModelVo channelroomPriceModelVo;
        RoomStatusModelVo roomStatusModelVo;
        RoomStatusModelVo qunarRoomStatusModelVo;
        RoomStatusModelVo b2bRoomStatusModelVo;
        RoomStatusModelVo channelRoomStatusModelVo;
        RoomInventoryModelVo roomInventoryModelVo;
        //渠道名称
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        String QunarChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
        String b2bChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
        String channelChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_CHANNEL_A.getName());
        for (MtHotelGoodsPriceBaseDetailVo mtHotelGoodsPriceBaseDetailVo : mtHotelGoodsPriceBaseDetailVos) {
            if(DateUtil.commpareDay(time,mtHotelGoodsPriceBaseDetailVo.getDate())){
                time=mtHotelGoodsPriceBaseDetailVo.getDate();
            }
            //携程
            roomDataEntityVo = new RoomDataEntityVo();
            roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //去哪儿
            qunarRoomDataEntityVo = new RoomDataEntityVo();
            qunarRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //B2B
            b2bRoomDataEntityVo = new RoomDataEntityVo();
            b2bRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //channelA
            channelaRoomDataEntityVo = new RoomDataEntityVo();
            channelaRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //针对统一的进行价格公式计算
            map = new HashMap<>();
            //判断是否参加促销活动
            switchHotelActiveTagEntity = switchHotelActiveTagMapper.selectHotelIdAndRoomIdAndTime(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(), mtHotelGoodsPriceBaseDetailVo.getDate());
            if (ObjectUtils.isEmpty(switchHotelActiveTagEntity)) {
                map = getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), null);
            } else {
                String currentWeekDay = DateUtil.dayForWeek(mtHotelGoodsPriceBaseDetailVo.getDate());
                //促销
                if (switchHotelActiveTagEntity.getWeek().contains("每天") || switchHotelActiveTagEntity.getWeek().contains(currentWeekDay)) {
                    map = getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), switchHotelActiveTagEntity);
                } else {//判断当前周几，是否符合促销活动
                    map = getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), null);
                }
            }
            //如果价格符合公式，房态可预定 有库存就进行设置推送
            price = Double.parseDouble(map.get("ctripPrice").toString());
            channelPrice = Double.parseDouble(map.get("qunarPrice").toString());
            //房价推送实体
            //携程
            roomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            roomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //去哪儿
            qunarRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            qunarRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //b2b
            b2bRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            b2bRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //channelA
            channelaRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            channelaRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //携程房价实体
            roomPriceModelVo = new RoomPriceModelVo();
            roomPriceModelVo.setRoomPrice(price);
            roomPriceModelVo.setCurrency("CNY");
            //去哪儿房价实体
            qunarroomPriceModelVo = new RoomPriceModelVo();
            qunarroomPriceModelVo.setRoomPrice(channelPrice);
            qunarroomPriceModelVo.setCurrency("CNY");
            //b2b房价实体
            b2broomPriceModelVo = new RoomPriceModelVo();
            BeanUtils.copyProperties(b2broomPriceModelVo, qunarroomPriceModelVo);
            //channel房价实体
            channelroomPriceModelVo = new RoomPriceModelVo();
            BeanUtils.copyProperties(channelroomPriceModelVo, qunarroomPriceModelVo);
            //携程
            roomPriceModelVo.setChannel(channel);
            roomDataEntityVo.setRoomPriceModel(roomPriceModelVo);
            //去哪儿
            qunarroomPriceModelVo.setChannel(QunarChannel);
            qunarRoomDataEntityVo.setRoomPriceModel(qunarroomPriceModelVo);
            //b2b
            b2broomPriceModelVo.setChannel(b2bChannel);
            b2bRoomDataEntityVo.setRoomPriceModel(b2broomPriceModelVo);
            //channelA
            channelroomPriceModelVo.setChannel(channelChannel);
            channelaRoomDataEntityVo.setRoomPriceModel(channelroomPriceModelVo);
            //遍历取消规则
      /*      for(MtHotelGoodsCancelRuleReturnVo mtHotelGoodsCancelRuleReturnVo:mtHotelGoodsCancelRuleReturnVos){
                //匹配同一天日期
                if (mtHotelGoodsPriceBaseDetailVo.getDate().equals(mtHotelGoodsCancelRuleReturnVo.getDate())) {
                    SaleRuleModelVo saleRuleModelVo=new SaleRuleModelVo();
                    //携程
                    CtripSellRuleVo ctripSellRuleVo=new CtripSellRuleVo();
                    //不可取消
                    if(mtHotelGoodsCancelRuleReturnVo.getCancelType()==0){
                        ctripSellRuleVo.setCancelType(1);
                        ctripSellRuleVo.setOverduePaymentType("F");
                        saleRuleModelVo.setCtripSellRule(ctripSellRuleVo);
                        saleRuleModelVo.setChannel(QunarChannel);
                        qunarRoomDataEntityVo.setSaleRuleModel(saleRuleModelVo);
                    }else{//可以取消
                        ctripSellRuleVo.setCancelType(2);
                        //提前取消时间类型 0 时间  1 时间量
                        if(mtHotelGoodsCancelRuleReturnVo.getDeductType()==0){
                            ctripSellRuleVo.setLatestCancelTimeOfDays(mtHotelGoodsCancelRuleReturnVo.getAheadCancelDays());
                            ctripSellRuleVo.setLatestCancelTimeOfHours(Integer.parseInt(Arrays.stream(mtHotelGoodsCancelRuleReturnVo.getAheadCancelHours().split(":")).findFirst().get()));
                            ctripSellRuleVo.setOverduePaymentType("F");
                        }else{
                            ctripSellRuleVo.setLatestCancelTimeOfDays(mtHotelGoodsCancelRuleReturnVo.getAheadCancelDays());
                            int hours=Integer.parseInt(mtHotelGoodsCancelRuleReturnVo.getAheadCancelHours());
                            ctripSellRuleVo.setLatestCancelTimeOfHours(24-hours);
                            ctripSellRuleVo.setOverduePaymentType("F");
                        }
                    }
                    saleRuleModelVo.setCtripSellRule(ctripSellRuleVo);
                    saleRuleModelVo.setChannel(channel);
                    roomDataEntityVo.setSaleRuleModel(saleRuleModelVo);
                }
            }*/
            if (mtHotelGoodsStatusDetailStateVos.size() < 1) {
                //携程房态实体
                roomStatusModelVo = new RoomStatusModelVo();
                //去哪儿房态实体
                qunarRoomStatusModelVo = new RoomStatusModelVo();
                //b2b房态实体
                b2bRoomStatusModelVo = new RoomStatusModelVo();
                //channel房态实体
                channelRoomStatusModelVo = new RoomStatusModelVo();
                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                roomStatusModelVo.setChannel(channel);
                roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                //去哪儿实体
                BeanUtils.copyProperties(qunarRoomStatusModelVo, roomStatusModelVo);
                qunarRoomStatusModelVo.setChannel(QunarChannel);
                qunarRoomDataEntityVo.setRoomStatusModel(qunarRoomStatusModelVo);
                //b2b实体
                BeanUtils.copyProperties(b2bRoomStatusModelVo, roomStatusModelVo);
                b2bRoomStatusModelVo.setChannel(b2bChannel);
                b2bRoomDataEntityVo.setRoomStatusModel(b2bRoomStatusModelVo);
                //channel实体
                BeanUtils.copyProperties(channelRoomStatusModelVo, roomStatusModelVo);
                channelRoomStatusModelVo.setChannel(channelChannel);
                channelaRoomDataEntityVo.setRoomStatusModel(channelRoomStatusModelVo);
                //库存推送实体
                roomInventoryModelVo = new RoomInventoryModelVo();
                //可以取消设置为保留房 不可以取消设置为非保留房
                isCanCancel = false;
             /*   if (isCanCancel) {
                    roomInventoryModelVo.setPreservedQuantity(1);
                    roomInventoryModelVo.setUnPreservedQuantity(0);
                } else {
                    roomInventoryModelVo.setPreservedQuantity(0);
                    roomInventoryModelVo.setUnPreservedQuantity(1);
                }*/
                roomInventoryModelVo.setPreservedQuantity(1);
                roomInventoryModelVo.setUnPreservedQuantity(0);
                //mtHotelGoodsPriceBaseDetailVo.getDate()>= time 推送的最晚时间
                String end="2020-01-08";
                if(DateUtil.commpareDay(time,mtHotelGoodsPriceBaseDetailVo.getDate())){
                    if(DateUtil.commpareDay(mtHotelGoodsPriceBaseDetailVo.getDate(),end)){
                        roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                        roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                    }else{
                        roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.ADD.getCode());
                        roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.ADD.getCode());
                    }
                }else{
                    roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                    roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                }
                roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                roomInventoryModelVo.setChannel(QunarChannel);
                qunarRoomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                roomDataEntityVos.add(b2bRoomDataEntityVo);
                roomDataEntityVos.add(channelaRoomDataEntityVo);
                roomDataEntityVos.add(roomDataEntityVo);
                roomDataEntityVos.add(qunarRoomDataEntityVo);
            } else {
                //遍历房态
                for (MtHotelGoodsStatusDetailStateVo mtHotelGoodsStatusDetailStateVo : mtHotelGoodsStatusDetailStateVos) {
                    //匹配同一天日期
                    if (mtHotelGoodsPriceBaseDetailVo.getDate().equals(mtHotelGoodsStatusDetailStateVo.getDate())) {
                        //房态推送实体
                        roomStatusModelVo = new RoomStatusModelVo();
                        if (mtHotelGoodsStatusDetailStateVo.getStatus() == 1) {
                            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                        } else {
                            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                        }
                        roomStatusModelVo.setChannel(channel);
                        roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                        //房量推送实体
                        roomInventoryModelVo = new RoomInventoryModelVo();
                        //可以取消设置为保留房 不可以取消设置为非保留房
                        isCanCancel = false;
                        if (isCanCancel) {
                            roomInventoryModelVo.setPreservedQuantity(1);
                            roomInventoryModelVo.setUnPreservedQuantity(0);
                        } else {
                            roomInventoryModelVo.setPreservedQuantity(0);
                            roomInventoryModelVo.setUnPreservedQuantity(1);
                        }
                        roomInventoryModelVo.setPreservedQuantity(0);
                        roomInventoryModelVo.setUnPreservedQuantity(1);
                        roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.REMAIN.getCode());
                        roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.REMAIN.getCode());
                        //mtHotelGoodsPriceBaseDetailVo.getDate()>= time 推送的最晚时间
                        /*if(!DateUtil.commpareDay(mtHotelGoodsPriceBaseDetailVo.getDate(),time)){
                            roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.ADD.getCode());
                            roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.ADD.getCode());
                        }else{
                            roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                            roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                        }*/
                        roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                        roomInventoryModelVo.setChannel(channel);
                        roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                        roomDataEntityVos.add(roomDataEntityVo);
                        roomDataEntityVos.add(qunarRoomDataEntityVo);
                        roomDataEntityVos.add(b2bRoomDataEntityVo);
                        roomDataEntityVos.add(channelaRoomDataEntityVo);
                    }
                }
            }
        }
        return roomDataEntityVos;
    }

    /**
     * @author: lmf
     * @date: 2020/9/11 16:24
     * 是否参与天天特价活动，如果参与价格增加
     */
    @Override
    public Map<String, Object> getPriceV2(Map<String, List<SwitchPriceBaseSetEntity>> priceSetMap, Integer salePrice, Integer subPrice, SwitchHotelActiveTagEntity switchHotelActiveTagEntity) {
        Map<String, Object> map = new HashMap<>();
        //计算携程渠道价格
        double ctripPrice = salePrice.doubleValue() / 100;
        double ctripRate = 0;
        double ctripAddPrice = 0;
        List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntitiesByCtril = priceSetMap.get(SwitchChannelNameEnums.CTRIP.getName());
        for (SwitchPriceBaseSetEntity switchPriceBaseSetEntity : switchPriceBaseSetEntitiesByCtril) {
            if (switchPriceBaseSetEntity.getMinPrice().doubleValue() <= ctripPrice && ctripPrice < switchPriceBaseSetEntity.getMaxPrice().doubleValue()) {
                ctripPrice = (salePrice.doubleValue() / 100 - subPrice.doubleValue() / 100) * (1 + switchPriceBaseSetEntity.getRate().doubleValue() / 100) + switchPriceBaseSetEntity.getAddPrice().doubleValue();
                ctripRate = switchPriceBaseSetEntity.getRate().doubleValue();
                ctripAddPrice = switchPriceBaseSetEntity.getAddPrice().doubleValue();
            }
        }
        //计算去哪儿渠道价格
        double qunarPrice = salePrice.doubleValue() / 100;
        double qunarRate = 0;
        double qunarAddPrice = 0;
        List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntitiesByQunar = priceSetMap.get(SwitchChannelNameEnums.QUNAR.getName());
        for (SwitchPriceBaseSetEntity switchPriceBaseSetEntity : switchPriceBaseSetEntitiesByQunar) {
            if (switchPriceBaseSetEntity.getMinPrice().doubleValue() <= qunarPrice && qunarPrice < switchPriceBaseSetEntity.getMaxPrice().doubleValue()) {
                qunarPrice = (salePrice.doubleValue() / 100 - subPrice.doubleValue() / 100) * (1 + switchPriceBaseSetEntity.getRate().doubleValue() / 100) + switchPriceBaseSetEntity.getAddPrice().doubleValue();
                qunarRate = switchPriceBaseSetEntity.getRate().doubleValue();
                qunarAddPrice = switchPriceBaseSetEntity.getAddPrice().doubleValue();
            }
        }
        if (!ObjectUtils.isEmpty(switchHotelActiveTagEntity)) {
            //促销方式是按折扣还是按金额
            if (switchHotelActiveTagEntity.getGenre() == 0) {
                qunarPrice =(qunarPrice * (1 - switchHotelActiveTagEntity.getRate().doubleValue() / 10)) + qunarPrice;
                ctripPrice = (qunarPrice * (1 - switchHotelActiveTagEntity.getRate().doubleValue() / 10)) + ctripPrice;
            } else {//按固定金额
                log.info("============switchHotelActiveTagEntity.getRate()的值为{}===",switchHotelActiveTagEntity.getRate());
                qunarPrice = qunarPrice + switchHotelActiveTagEntity.getRate().doubleValue();
                ctripPrice = ctripPrice + switchHotelActiveTagEntity.getRate().doubleValue();
            }
        }
        BigDecimal bg = new BigDecimal(ctripPrice);
        ctripPrice=bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        BigDecimal bg2 = new BigDecimal(qunarPrice);
        qunarPrice=bg2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        map.put("ctripPrice", ctripPrice);
        map.put("ctripRate", ctripRate);
        map.put("ctripAddPrice", ctripAddPrice);
        map.put("qunarPrice", qunarPrice);
        map.put("qunarRate", qunarRate);
        map.put("qunarAddPrice", qunarAddPrice);
        return map;
    }

    @Override
    public Result<Object> notityModifyRoomInfo(BatchPushRoomDatasVo batchPushRoomDatasVo) {
        return null;
    }

    /**
     * 计算价格 公式一 针对所有房型
     *
     * @Param mtPrice 美团产品的价格 以分为单位
     * @Param price 美团产品的价格 上一次推送时获取的美团产品的价格
     * @Param add_price 携程在美团上面多加的价格
     * @Param rate 携程按照比例在美团的价格加的比例
     * a<180 6%  180<=a<500 2.8%  500 6%
     */
    public Map<String, String> getPrice(SwitchRoomPriceSetEntity switchRoomPriceSetEntity, Integer mtPrices, double price, double add_price, double rate) {
        Map<String, String> result = new HashMap<>();
        double mtPrice = mtPrices.doubleValue() / 100;
        float finallyPrice = 0;
        if (switchRoomPriceSetEntity.getGenre() == 0) {//按比例
            double rate2 = switchRoomPriceSetEntity.getRate();
            //如果美团价格变动重新开始
            if (mtPrice == price) {
                if (rate != 1) {//说明已经调整到底
                    result.put("rate", String.valueOf(rate - 1));
                    result.put("add_price", "0");
                    finallyPrice = (float) (mtPrice + mtPrice * ((rate - 1) / 100));
                } else {
                    finallyPrice = (float) mtPrice;
                }
            } else {
                result.put("rate", String.valueOf(rate2));
                result.put("add_price", "0");
                finallyPrice = (float) (mtPrice + mtPrice * (rate2 / 100));
            }
        } else {//按价格
            double minPrice = switchRoomPriceSetEntity.getMinPrice();
            double maxPrice = switchRoomPriceSetEntity.getMaxPrice();
            //说明美团的价格没有变动,相当于我们降低价格
            if (mtPrice == price) {
                if (add_price != minPrice) {//说明已经调整到最低
                    result.put("add_price", String.valueOf(add_price - 1));
                    result.put("rate", "0");
                    finallyPrice = (float) (mtPrice + (add_price - 1));
                } else {
                    finallyPrice = (float) mtPrice;
                }
            } else {//说明美团的价格变动,跟我们
                result.put("add_price", String.valueOf(maxPrice));
                result.put("rate", "0");
                finallyPrice = (float) (mtPrice + maxPrice);
            }
        }
        result.put("price", String.valueOf(finallyPrice));
        return result;
    }

    /**
     * @author: lmf
     * @date: 2020/9/3 14:07
     * 按照美团的价格上架
     */
    public Map<String, String> getOldPrice(SwitchRoomPriceSetEntity switchRoomPriceSetEntity, Integer mtPrices, double price, double add_price, double rate) {
        Map<String, String> result = new HashMap<>();
        double mtPrice = mtPrices.doubleValue() / 100;
        float finallyPrice = 0;
        if (switchRoomPriceSetEntity.getGenre() == 0) {//按比例
            double rate2 = switchRoomPriceSetEntity.getRate();
            //如果美团价格变动重新开始
            if (mtPrice == price) {
                if (rate != 1) {//说明已经调整到底
                    result.put("rate", String.valueOf(rate - 1));
                    result.put("add_price", "0");
                    finallyPrice = (float) (mtPrice + mtPrice * ((rate - 1) / 100));
                } else {
                    finallyPrice = (float) mtPrice;
                }
            } else {
                result.put("rate", String.valueOf(rate2));
                result.put("add_price", "0");
                finallyPrice = (float) (mtPrice + mtPrice * (rate2 / 100));
            }
        } else {//按价格
            double minPrice = switchRoomPriceSetEntity.getMinPrice();
            double maxPrice = switchRoomPriceSetEntity.getMaxPrice();
            //说明美团的价格没有变动,相当于我们降低价格
            if (mtPrice == price) {
                if (add_price != minPrice) {//说明已经调整到最低
                    result.put("add_price", String.valueOf(add_price - 1));
                    result.put("rate", "0");
                    finallyPrice = (float) (mtPrice + (add_price - 1));
                } else {
                    finallyPrice = (float) mtPrice;
                }
            } else {//说明美团的价格变动,跟我们
                result.put("add_price", String.valueOf(maxPrice));
                result.put("rate", "0");
                finallyPrice = (float) (mtPrice + maxPrice);
            }
        }
        result.put("price", String.valueOf(finallyPrice));
        return result;
    }

    /**
     * 计算价格 公式二 针对参与促销活动的标签
     *
     * @Param mtPrice 美团产品的价格 以分为单位
     * @Param price 美团产品的价格 上一次推送时获取的美团产品的价格
     * @Param add_price 携程在美团上面多加的价格
     * @Param rate 携程按照比例在美团的价格加的比例
     */
    private Map<String, String> getLabelPrice(SwitchRoomPriceSetEntity switchRoomPriceSetEntity, SwitchHotelActiveTagEntity switchHotelActiveTagEntity, Integer mtPrices, double price, double add_price, double rate) {
        Map<String, String> result = new HashMap<>();
        double mtPrice = mtPrices.doubleValue() / 100;
        float finallyPrice = 0;
        if (switchRoomPriceSetEntity.getGenre() == 0) {//按比例
            double rate2 = switchRoomPriceSetEntity.getRate();
            //如果美团价格变动重新开始
            if (mtPrice == price) {
                if (rate != 1) {//说明已经调整到底
                    result.put("rate", String.valueOf(rate - 1));
                    result.put("add_price", "0");
                    finallyPrice = (float) (mtPrice + mtPrice * ((rate - 1) / 100));
                } else {
                    finallyPrice = (float) mtPrice;
                }
            } else {
                result.put("rate", String.valueOf(rate2));
                result.put("add_price", "0");
                finallyPrice = (float) (mtPrice + mtPrice * (rate2 / 100));
            }
        } else {//按价格
            double minPrice = switchRoomPriceSetEntity.getMinPrice();
            double maxPrice = switchRoomPriceSetEntity.getMaxPrice();
            //说明美团的价格没有变动,相当于我们降低价格
            if (mtPrice == price) {
                if (add_price != minPrice) {//说明已经调整到最低
                    result.put("add_price", String.valueOf(add_price - 1));
                    result.put("rate", "0");
                    finallyPrice = (float) (mtPrice + (add_price - 1));
                } else {
                    finallyPrice = (float) mtPrice;
                }
            } else {//说明美团的价格变动,跟我们
                result.put("add_price", String.valueOf(maxPrice));
                result.put("rate", "0");
                finallyPrice = (float) (mtPrice + maxPrice);
            }
        }
        //促销方式是按折扣还是按金额
        if (switchHotelActiveTagEntity.getGenre() == 0) {
            finallyPrice = (float) (finallyPrice * 1.112 * (1 - switchHotelActiveTagEntity.getRate().floatValue() / 10)) + finallyPrice;
        } else {//按固定金额
            finallyPrice = finallyPrice + switchHotelActiveTagEntity.getRate().floatValue();
        }
        result.put("price", String.valueOf(finallyPrice));
        return result;
    }

    /**
     * @author: lmf
     * @date: 2020/9/3 14:12
     * 按照美团的原价
     */
    private Map<String, String> getOldLabelPrice(SwitchHotelActiveTagEntity switchHotelActiveTagEntity, Integer mtPrices, double price, double add_price, double rate) {
        Map<String, String> result = new HashMap<>();
        double mtPrice = mtPrices.doubleValue() / 100;
        float finallyPrice = (float) mtPrice;
        result.put("add_price", "0");
        result.put("rate", "0");
        //促销方式是按折扣还是按金额
        if (switchHotelActiveTagEntity.getGenre() == 0) {
            finallyPrice = (float) (finallyPrice * 1.112 * (1 - switchHotelActiveTagEntity.getRate().floatValue() / 10)) + finallyPrice;
        } else {//按固定金额
            finallyPrice = finallyPrice + switchHotelActiveTagEntity.getRate().floatValue();
        }
        result.put("price", String.valueOf(finallyPrice));
        return result;
    }
    /**
     * 分页获取可推送价格的房型列表
     * @param page
     * @return
     */
    @Override
    /* @Retryable(value = Exception.class, maxAttempts = 4, backoff = @Backoff(delay = 2000, multiplier = 1.5))*/
    public Result<Map<Integer, Object>> getCanPushRoomList(int page) {
        //1.获取可以进行推送的数据
        //String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    /*    String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        int day=3;
        String endTime=DateUtil.getNextDays(day);
        List<RoomResultVo> roomResultVos = switchCreateRoomMapper.selectRoomIdByTime(endTime, time, (page - 1) * 6);
        if (roomResultVos.size() < 1) {
            return new Result<>(new HashMap<>());
        }
        Map<Integer, Object> result = new HashMap<>();
        for (RoomResultVo roomResultVo : roomResultVos) {
            result.put(roomResultVo.getRoomId(), roomResultVo.getHotelId());
        }*/
        return new Result<>();
    }
    /**
     * 推送库存
     *
     * @param modifyRemainVo
     * @return
     */
    public Result<Object> modifyRemain(ModifyRemainVo modifyRemainVo) {
        log.info("==================调用美团预下单推送库存{}======================", JSON.toJSONString(modifyRemainVo));
        //从售卖房型表获取美团的产品id
        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectMtRoomIdByRoomIdAndHotelId(modifyRemainVo.getHotelId(), modifyRemainVo.getRoomId());
        if (ObjectUtils.isEmpty(switchCreateRoomEntity)) {
            return new Result<>("没有找到当天的推送数据,请检查传递日期是否正确");
        }
        log.info("================获取售卖房型的取消规则start===========");
        boolean isCandeuce = false;
        log.info("================获取售卖房型的取消规则end=-======");
        BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
        batchPushRoomVo.setHotelId(modifyRemainVo.getHotelId());
        //获取结束日期
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        //封装推送房量的推送实体
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        RoomDataEntityVo roomDataEntityVo = new RoomDataEntityVo();
        roomDataEntityVo.setRoomId(modifyRemainVo.getRoomId());
        roomDataEntityVo.setStartDate(modifyRemainVo.getTime());
        roomDataEntityVo.setEndDate(DateUtil.getUpDate(modifyRemainVo.getEndTime(),1));
        RoomInventoryModelVo roomInventoryModelVo = new RoomInventoryModelVo();
        isCandeuce=false;
        if (isCandeuce) {
            roomInventoryModelVo.setPreservedQuantity(modifyRemainVo.getNum());
            roomInventoryModelVo.setUnPreservedQuantity(0);
        } else {
            roomInventoryModelVo.setPreservedQuantity(0);
            roomInventoryModelVo.setUnPreservedQuantity(modifyRemainVo.getNum());
        }
        roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
        roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
        roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
        roomInventoryModelVo.setChannel(channel);
        RoomStatusModelVo roomStatusModelVo=new RoomStatusModelVo();
        if(modifyRemainVo.getNum()==0){
            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
            roomInventoryModelVo.setUnPreservedQuantity(1);
        }else{
            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
        }
        roomStatusModelVo.setChannel(channel);
        roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
        roomDataEntityVos.add(roomDataEntityVo);
        roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
        if (ObjectUtils.isEmpty(roomDataEntityVos) || roomDataEntityVos.size() < 1) {
            log.info("==============推送的实体为空=======================");
            return new Result<>("推送的实体为空");
        }
        log.info("==============调用美团预下单修改库存开始====创建推送放量实体=======================");
        batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
        //6.调用直连推送报价
        Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
        SendUtils.dingMsg("美团预下单推送库存-直连推送报价等数据接口酒店id" + batchPushRoomVo.getHotelId(), "请求状态" + result.getMsg().toString(), 1, restTemplate);
        if (result.getCode() == CommonConstants.SUCCESS) {
            return new Result<>(CommonConstants.SUCCESS, "=======推送放量实体成功========");
        } else {
            if(result.getMsg().toString().contains("频繁")){
                try {
                    Thread.sleep(1000);
                    result=switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            log.info("=======推送放量实体失败,原因为{}========", result.getMsg());
            return new Result<>("=======推送放量实体失败,原因为{}========" + result.getMsg());
        }
    }

    /**
     * 推送价格
     *
     * @param modifyPriceVo
     * @return
     */
    public Result<Object> modifyPrice(ModifyPriceVo modifyPriceVo) throws Exception {
        //1.获取对应的产品id
        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectByMtGoodsIdAndHotelId(modifyPriceVo.getMtHotelId(), modifyPriceVo.getMtGoodId());
        //2.先效验房态
       /* int mtGoodId = modifyPriceVo.getMtGoodId();
        int mtHotelId = modifyPriceVo.getMtHotelId();
        int masterHotelId = switchCreateRoomEntity.getMasterHotelId();
        int mtRoomId = Integer.parseInt(switchCreateRoomEntity.getMtRoomId());
        Map<String, Object> params = new HashMap<>();
        params.put("startDate", modifyPriceVo.getTime());
        params.put("endDate", DateUtil.getNextDay(modifyPriceVo.getTime()));
        params.put("hotelId", mtHotelId);
        List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos = getMtGoodsStatus(params, mtGoodId);
        if (ObjectUtils.isEmpty(mtHotelGoodsStatusDetailStateVos) || mtHotelGoodsStatusDetailStateVos.size() < 1) {
            log.info("====================获取不到对应的美团产品{}的房态信息===========", mtGoodId);
            return new Result<>("获取不到当日的房态信息");
        }
        MtHotelGoodsStatusDetailStateVo mtHotelGoodsStatusDetailStateVo = mtHotelGoodsStatusDetailStateVos.get(0);*/
        //判断该产品对应的售卖是否房型是否下架，如果是下架状态重新上架
        double mtPrice = modifyPriceVo.getPrice().doubleValue() / 100;
        //4.美团价格变动 跟的变
        Map<String, List<SwitchPriceBaseSetEntity>> switchPriceSetMap = getOnlinePriceSet();
        log.info("==============创建推送价格实体=======================");
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        List<SwitchPushRoomDataAllEntity> pushRoomDataAllEntities = new ArrayList<>();
        //推送价格记录表
      /*  SwitchPushRoomDataAllEntity pushRoomDataEntity = new SwitchPushRoomDataAllEntity();
        SwitchPushRoomDataAllEntity switchPushRoomDataEntity = new SwitchPushRoomDataAllEntity();*/
        /*    switchPushRoomDataEntity.setId(StringUtil.getUUID());*/
        //携程
        RoomDataEntityVo roomDataEntityVo = new RoomDataEntityVo();
        roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        //去哪儿
        RoomDataEntityVo qunarRoomDataEntityVo = new RoomDataEntityVo();
        qunarRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        //b2b
        RoomDataEntityVo b2bRoomDataEntityVo = new RoomDataEntityVo();
        b2bRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        //channel
        RoomDataEntityVo channelRoomDataEntityVo = new RoomDataEntityVo();
        channelRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        //如果价格符合公式，房态可预定 有库存就进行设置推送
        Map<String, Object> map = new HashMap<>();
        //判断是否参加促销活动
        SwitchHotelActiveTagEntity switchHotelActiveTagEntity = switchHotelActiveTagMapper.selectHotelIdAndRoomIdAndTime(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(), modifyPriceVo.getTime());
        if (ObjectUtils.isEmpty(switchHotelActiveTagEntity)) {
            log.info("============该房型在{}没有参与促销活动========", modifyPriceVo.getTime());
            map = getPriceV2(switchPriceSetMap, modifyPriceVo.getPrice(), modifyPriceVo.getSubPrice(), null);
        } else {
            String currentWeekDay = DateUtil.dayForWeek(modifyPriceVo.getTime());
            //促销
            if (switchHotelActiveTagEntity.getWeek().contains("每天") || switchHotelActiveTagEntity.getWeek().contains(currentWeekDay)) {
                map = getPriceV2(switchPriceSetMap, modifyPriceVo.getPrice(), modifyPriceVo.getSubPrice(), switchHotelActiveTagEntity);
            } else {//判断当前周几，是否符合促销活动
                map = getPriceV2(switchPriceSetMap, modifyPriceVo.getPrice(), modifyPriceVo.getSubPrice(), null);
            }
        }
        //Map<String, String> map = getPrice(switchRoomPriceSetEntity, modifyPriceVo.getPrice()-modifyPriceVo.getSubPrice(), switchPushRoomDataEntity.getMtPrice()-switchPushRoomDataEntity.getMtSubPrice(), 0, 0);
        double price = Double.parseDouble(map.get("ctripPrice").toString());
        //根据渠道公式算出来的价格公式
        double priceByChannel = Double.parseDouble(map.get("qunarPrice").toString());
        //推送价格记录表
      /*  pushRoomDataEntity.setId(StringUtil.getUUID());
        pushRoomDataEntity.setHotelId(switchCreateRoomEntity.getHotelId());
        pushRoomDataEntity.setRoomId(switchCreateRoomEntity.getRoomId());
        pushRoomDataEntity.setMtHotelId(mtHotelId);
        pushRoomDataEntity.setMasterHotelId(masterHotelId);
        pushRoomDataEntity.setMtGoodId(mtGoodId);
        pushRoomDataEntity.setPrice(price);
        pushRoomDataEntity.setAddPrice(Double.valueOf(map.get("ctripAddPrice").toString()));
        pushRoomDataEntity.setRate(Double.valueOf(map.get("ctripRate").toString()));
        pushRoomDataEntity.setPriceRate(price + price * 0.12);
        pushRoomDataEntity.setMtPrice(mtPrice);
        pushRoomDataEntity.setMtSubPrice(modifyPriceVo.getSubPrice().doubleValue() / 100);
        pushRoomDataEntity.setStatus(0);
        pushRoomDataEntity.setRemark("");
        pushRoomDataEntity.setStartTime(modifyPriceVo.getTime());
        pushRoomDataEntity.setEndTime(modifyPriceVo.getTime());
        pushRoomDataEntity.setSale(1);
        pushRoomDataEntity.setMtRoomId(mtRoomId);*/
        //房价推送实体
        roomDataEntityVo.setStartDate(modifyPriceVo.getTime());
        roomDataEntityVo.setEndDate(modifyPriceVo.getTime());
        qunarRoomDataEntityVo.setStartDate(modifyPriceVo.getTime());
        qunarRoomDataEntityVo.setEndDate(modifyPriceVo.getTime());
        b2bRoomDataEntityVo.setStartDate(modifyPriceVo.getTime());
        b2bRoomDataEntityVo.setEndDate(modifyPriceVo.getTime());
        channelRoomDataEntityVo.setStartDate(modifyPriceVo.getTime());
        channelRoomDataEntityVo.setEndDate(modifyPriceVo.getTime());
        //渠道
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        String QunarChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
        String b2bChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
        String channelChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_CHANNEL_A.getName());
        //携程
        RoomPriceModelVo roomPriceModelVo = new RoomPriceModelVo();
        roomPriceModelVo.setRoomPrice(price);
        roomPriceModelVo.setCurrency("CNY");
        roomPriceModelVo.setChannel(channel);
        //去哪儿
        RoomPriceModelVo qunarroomPriceModelVo = new RoomPriceModelVo();
        qunarroomPriceModelVo.setRoomPrice(priceByChannel);
        qunarroomPriceModelVo.setCurrency("CNY");
        //b2b
        RoomPriceModelVo b2broomPriceModelVo = new RoomPriceModelVo();
        //channel
        RoomPriceModelVo channelroomPriceModelVo = new RoomPriceModelVo();
        //BeanUtils.copyProperties(qunarroomPriceModelVo, roomPriceModelVo);
        BeanUtils.copyProperties(b2broomPriceModelVo, qunarroomPriceModelVo);
        BeanUtils.copyProperties(channelroomPriceModelVo, qunarroomPriceModelVo);
        roomDataEntityVo.setRoomPriceModel(roomPriceModelVo);
        //去哪儿
        qunarroomPriceModelVo.setChannel(QunarChannel);
        qunarRoomDataEntityVo.setRoomPriceModel(qunarroomPriceModelVo);
        //b2b
        b2broomPriceModelVo.setChannel(b2bChannel);
        b2bRoomDataEntityVo.setRoomPriceModel(b2broomPriceModelVo);
        //channel
        channelroomPriceModelVo.setChannel(channelChannel);
        channelRoomDataEntityVo.setRoomPriceModel(channelroomPriceModelVo);
        //3.如果该售卖房型对应的美团产品为不可预定，那么就得设置为满房了
        RoomStatusModelVo roomStatusModelVo = new RoomStatusModelVo();
        roomStatusModelVo.setChannel(channel);
     /*   if (mtHotelGoodsStatusDetailStateVo.getStatus() != 1) {
            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
        } else {
            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
        }*/
        /*       roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);*/
        roomDataEntityVos.add(roomDataEntityVo);
        roomDataEntityVos.add(qunarRoomDataEntityVo);
        roomDataEntityVos.add(b2bRoomDataEntityVo);
        roomDataEntityVos.add(channelRoomDataEntityVo);
        //推送价格记录表 保存房型推送数据实体数据
       /* List<RoomDataEntityVo> roomDataEntityVo_temp = new ArrayList<>();
        roomDataEntityVo_temp.add(roomDataEntityVo);
        roomDataEntityVo_temp.add(qunarRoomDataEntityVo);
        pushRoomDataEntity.setFormData(JSONArray.fromObject(roomDataEntityVo_temp).toString());*/
        BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
        batchPushRoomVo.setHotelId(switchCreateRoomEntity.getHotelId());
        batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
        //6.调用直连推送报价
        Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
        SendUtils.dingMsg("直连推送报价等数据接口酒店id" + batchPushRoomVo.getHotelId(), "请求状态" + result.getMsg().toString(), 1, restTemplate);
        if (result.getCode() == CommonConstants.SUCCESS) {
            return new Result<>("=======推送价格成功========");
        } else {
            return new Result<>("=======推送价格实体失败========");
        }
    }

    /**
     * 更新房态
     *
     * @param modifyStatusVo
     * @return
     */
    @Override
    public Result<Object> modifyStaus(ModifyStatusVo modifyStatusVo) {
        //1.获取对应的产品id
       /* SwitchPushRoomDataAllEntity switchPushRoomDataEntity = switchPushRoomDataMapper.selectByGoodIdAndTime(modifyStatusVo.getMtGoodId(), modifyStatusVo.getTime());
        if (ObjectUtils.isEmpty(switchPushRoomDataEntity)) {
            return new Result<>("没有找到当天的推送数据,请检查传递日期是否正确");
        }*/
        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectByMtGoodsIdAndHotelId(modifyStatusVo.getMtHotelId(), modifyStatusVo.getMtGoodId());
        //2.先效验房态
        int mtGoodId = modifyStatusVo.getMtGoodId();
        int mtHotelId = modifyStatusVo.getMtHotelId();
        int masterHotelId = switchCreateRoomEntity.getMasterHotelId();
        int mtRoomId = Integer.parseInt(switchCreateRoomEntity.getMtRoomId());
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        RoomDataEntityVo roomDataEntityVo = roomStatus(switchCreateRoomEntity.getRoomId(), switchCreateRoomEntity.getHotelId(), masterHotelId, mtHotelId, mtGoodId, mtRoomId, modifyStatusVo.getTime(), modifyStatusVo.getStatus());
        roomDataEntityVos.add(roomDataEntityVo);
        BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
        batchPushRoomVo.setHotelId(switchCreateRoomEntity.getHotelId());
        batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
        //6.调用直连推送房态
        Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
        SendUtils.dingMsg("直连推送报价等数据接口酒店id" + batchPushRoomVo.getHotelId(), "请求状态" + result.getMsg().toString(), 1, restTemplate);
        if (result.getCode() == CommonConstants.SUCCESS) {
            Map<String, String> resultData = result.getData();
            for (SwitchPushRoomDataAllEntity pushRoomDataEntity : switchPushStatusEntities) {
                pushRoomDataEntity.setLogKey(resultData.get("logKey"));
                pushRoomDataEntity.setRemark("推送房态");
                pushRoomDataEntity.setStatus(0);
            }
            addLogToPushLog(switchPushStatusEntities);
            return new Result<>("=======推送房态成功========");
        } else {
            return new Result<>("=======推送房态失败========");
        }
    }


    /**
     * 变更房态
     */
    public RoomDataEntityVo roomStatus(int roomId, int hotelId, int masterHotelId, int mtHotelId, int mtGoodId, int mtRoomId, String time, int status) {
        log.info("==============创建推送房态实体=======================");
        //推送房态记录表
        SwitchPushRoomDataAllEntity pushRoomDataEntity = new SwitchPushRoomDataAllEntity();
        pushRoomDataEntity.setId(StringUtil.getUUID());
        RoomDataEntityVo roomDataEntityVo = new RoomDataEntityVo();
        roomDataEntityVo.setRoomId(roomId);
        //推送房态记录表
        pushRoomDataEntity.setId(StringUtil.getUUID());
        pushRoomDataEntity.setHotelId(hotelId);
        pushRoomDataEntity.setRoomId(roomId);
        pushRoomDataEntity.setMtHotelId(mtHotelId);
        pushRoomDataEntity.setMasterHotelId(masterHotelId);
        pushRoomDataEntity.setMtGoodId(mtGoodId);
        pushRoomDataEntity.setPrice(0.0);
        pushRoomDataEntity.setAddPrice(0.0);
        pushRoomDataEntity.setRate(0.0);
        pushRoomDataEntity.setPriceRate(0.0);
        pushRoomDataEntity.setMtPrice(0.0);
        pushRoomDataEntity.setMtSubPrice(0.0);
        pushRoomDataEntity.setStatus(0);
        pushRoomDataEntity.setRemark("房态变更");
        pushRoomDataEntity.setStartTime(time);
        pushRoomDataEntity.setEndTime(time);
        pushRoomDataEntity.setMtRoomId(mtRoomId);
        //房态推送实体
        roomDataEntityVo.setStartDate(time);
        roomDataEntityVo.setEndDate(time);
        RoomStatusModelVo roomStatusModelVo = new RoomStatusModelVo();
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
        roomStatusModelVo.setChannel(channel);
        roomStatusModelVo.setSaleStatus(status);
        pushRoomDataEntity.setSale(status);
        roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
        //库存
        RoomInventoryModelVo roomInventoryModelVo = new RoomInventoryModelVo();
        roomInventoryModelVo.setChannel(channel);
        roomInventoryModelVo.setUnPreservedQuantity(0);
        roomInventoryModelVo.setPreservedQuantity(0);
        roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
        roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
        //推送价格记录表 保存房型推送数据实体数据
        List<RoomDataEntityVo> roomDataEntityVo_temp = new ArrayList<>();
        roomDataEntityVo_temp.add(roomDataEntityVo);
        pushRoomDataEntity.setFormData(JSONArray.fromObject(roomDataEntityVo_temp).toString());
        switchPushStatusEntities.add(pushRoomDataEntity);
        switchPushRoomDataEntities.add(pushRoomDataEntity);
        return roomDataEntityVo;
    }

    /**
     * 效验是否可以接单
     *
     * @param canAcceptVo
     * @return
     */
    @Override
    public Result<Object> isCanAccept(CanAcceptVo canAcceptVo) {
/*        //1.获取产品id
        SwitchPushRoomDataEntity switchPushRoomDataEntity=switchPushRoomDataMapper.selectByGoodIdAndTime(canAcceptVo.getMtGoodId(),canAcceptVo.getStartTime());
        int mtGoodId=switchPushRoomDataEntity.getMtGoodId();
        //2.获取美团房价
        Map<String,Object> params=new HashMap<>();
        params.put("goodsId",mtGoodId);
        params.put("startDate",canAcceptVo.getStartTime());
        params.put("endDate", canAcceptVo.getEndTime());
        List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = getMtGoodsPrice(params);
        if(ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos)||mtHotelGoodsPriceBaseDetailVos.size()<1){
            log.info("===========美团的产品价格日历数据为空=============");
            return new Result<>(2);
        }
        MtHotelGoodsPriceBaseDetailVo mtHotelGoodsPriceBaseDetailVo=mtHotelGoodsPriceBaseDetailVos.get(0);
        double currentPrice=(double)mtHotelGoodsPriceBaseDetailVo.getSalePrice()/100;
        if(currentPrice>switchPushRoomDataEntity.getMtPrice()){
           return new Result<>(0);
        }else{
            return new Result<>(1);
        }*/
        //美团的订单总价格是根据美团预约下单返回的最新售卖价得来，只要价格低于携程的订单价格都可以接受
        //后期优化可能会携程操作 待完善
        //0 价格变高(拒绝订单)  1 价格变低(接受订单) 2 (获取美团的日历数据获取到空)  稍后重试 3 加了6%还是低于美团价格
        log.info("===================进入携程的isCanAccept方法=========================");
        double swPrice = canAcceptVo.getSwPrice() + 20;
        if (swPrice > canAcceptVo.getMtPrice().doubleValue()) {
            log.info("===================进入携程的isCanAccept方法,返回{}=========================", 1);
            return new Result<>(1);
        } else {
            log.info("===================进入携程的isCanAccept方法,返回{}=========================", 3);
            return new Result<>(3);
        }
    }

    /**
     * 根据logkey获取推送信息
     * 如果推送失败，重新推送
     *
     * @param logKey
     * @param type
     * @return
     */
    @Override
    public Result<Object> getPushRoomDataLog(String logKey, int type) {
        log.info("=====================开始获取日志信息===================");
        GetPushRoomDataLogVo getPushRoomDataLogVo = new GetPushRoomDataLogVo();
        getPushRoomDataLogVo.setRowKey(logKey);
        getPushRoomDataLogVo.setType(type);
        Result<Object> result = switchRoomPriceService.getPushRoomDataLog(getPushRoomDataLogVo);
        if (result.getCode() == CommonConstants.SUCCESS) {
            log.info("==================获取日志成功==================");
        } else {
            log.info("==================获取日志失败，失败信息为{}", result.getMsg());
        }
        return null;
    }

    /**
     * 下单前效验价格是否符合变化范围
     *
     * @param validPriceVo
     * @return
     */
    @Override
    public Result<Object> validStatus(ValidPriceVo validPriceVo) {
        log.info("======================请求下单效验价格的为{}==============", validPriceVo.toString());
        //1.获取产品id
        Integer mtRoomId = 0;
        Integer mtGoodId;
        Integer masterHotelId = 0;
        Integer mtHotelId = 0;
        //从售卖房型表获取美团的产品id
        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectMtRoomIdByRoomIdAndHotelId(validPriceVo.getHotelId(), validPriceVo.getRoomId());
        if (ObjectUtils.isEmpty(switchCreateRoomEntity)) {
            return new Result<>(SwitchValidPriceStatusEnums.NOTFIND.getCode(), SwitchValidPriceStatusEnums.NOTFIND.getMsg());
        } else {
            mtRoomId = Integer.valueOf(switchCreateRoomEntity.getMtRoomId());
            mtGoodId = switchCreateRoomEntity.getMtGoodId();
            masterHotelId = switchCreateRoomEntity.getMasterHotelId();
            mtHotelId = switchCreateRoomEntity.getMtHotelId();
        }
        //2.获取美团房价
        Map<String, Object> params = new HashMap<>();
        params.put("goodsId", mtGoodId);
        params.put("startDate", validPriceVo.getTime());
        params.put("endDate", validPriceVo.getEndTime());
        params.put("roomId", mtRoomId);
        MtHotelGoodsInventoryVo mtHotelGoodsInventoryVo = getMtGoodsInventory(params);
        if (mtHotelGoodsInventoryVo == null) {
            return new Result<>(SwitchValidPriceStatusEnums.NETWORK.getCode(), SwitchValidPriceStatusEnums.NETWORK.getMsg());
        }
        log.info("==============产品库存信息为{}", mtHotelGoodsInventoryVo.toString());
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        if (ObjectUtils.isEmpty(mtHotelGoodsInventoryVo) || BeanToolUtils.checkFieldValueNull(mtHotelGoodsInventoryVo)) {
            log.info("===============美团的产品库存为空=======================");
            //更新房态为满房
            RoomDataEntityVo roomDataEntityVo = roomStatus(validPriceVo.getRoomId(), validPriceVo.getHotelId(), masterHotelId, mtHotelId, mtGoodId, mtRoomId, validPriceVo.getTime(), 0);
            roomDataEntityVos.add(roomDataEntityVo);
            BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
            batchPushRoomVo.setHotelId(validPriceVo.getHotelId());
            batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
            //调用直连推送房态
            Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
            SendUtils.dingMsg("下单前效验-直连推送报价等数据接口酒店id" + batchPushRoomVo.getHotelId(), "请求状态" + result.getMsg().toString(), 1, restTemplate);
            if (result.getCode() == CommonConstants.SUCCESS) {
                Map<String, String> resultData = result.getData();
                for (SwitchPushRoomDataAllEntity pushRoomDataEntity : switchPushStatusEntities) {
                    pushRoomDataEntity.setLogKey(resultData.get("logKey"));
                    pushRoomDataEntity.setRemark("房态变更");
                    pushRoomDataEntity.setStatus(0);
                }
                //添加记录
                addLogToPushLog(switchPushStatusEntities);
            }
            return new Result<>(SwitchValidPriceStatusEnums.REMAIN.getCode(), SwitchValidPriceStatusEnums.REMAIN.getMsg());
        }
        log.info("=============下单前效验美团的库存===========================");
        if (mtHotelGoodsInventoryVo.getRemain() < 1) {
            RoomDataEntityVo roomDataEntityVo = roomStatus(validPriceVo.getRoomId(), validPriceVo.getHotelId(), masterHotelId, mtHotelId, mtGoodId, mtRoomId, validPriceVo.getTime(), 0);
            roomDataEntityVos.add(roomDataEntityVo);
            BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
            batchPushRoomVo.setHotelId(validPriceVo.getHotelId());
            batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
            //调用直连推送房态
            Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
            SendUtils.dingMsg("下单前效验-直连推送报价等数据接口酒店id" + batchPushRoomVo.getHotelId() + "售卖房型id为" + batchPushRoomVo.getRoomDataEntitys().get(0).getRoomId(), "请求状态" + result.getMsg().toString(), 1, restTemplate);
            if (result.getCode() == CommonConstants.SUCCESS) {
                Map<String, String> resultData = result.getData();
                for (SwitchPushRoomDataAllEntity pushRoomDataEntity : switchPushStatusEntities) {
                    pushRoomDataEntity.setLogKey(resultData.get("logKey"));
                    pushRoomDataEntity.setRemark("房态变更");
                    pushRoomDataEntity.setStatus(0);
                }
                addLogToPushLog(switchPushStatusEntities);
            }
            return new Result<>(SwitchValidPriceStatusEnums.REMAIN.getCode(), SwitchValidPriceStatusEnums.REMAIN.getMsg());
        }
        log.info("=============下单前效验美团的库存通过===========================");
        log.info("=============下单前效验携程的订单总价 美团的订单总价===========================");
        //价格过高 携程的订单总价 美团的订单总价
        List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = getMtGoodsPrice(params);
        if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
            return new Result<>("获取美团价格日历失败");
        }
        int mtPrice = 0;
        log.info("=============房价数为{}", validPriceVo.getNum());
        for (MtHotelGoodsPriceBaseDetailVo mtHotelGoodsPriceBaseDetailVo : mtHotelGoodsPriceBaseDetailVos) {
            mtPrice = mtPrice + ((mtHotelGoodsPriceBaseDetailVo.getSalePrice() - mtHotelGoodsPriceBaseDetailVo.getSubPrice()) * validPriceVo.getNum());
        }
        //可接受的价格范围为20块
        double switchPrice = validPriceVo.getPrice() * 100 + 20;
        if (mtPrice > switchPrice) {
            log.info("============美团的订单价格大于携程的订单价格===========");
            log.info("masterHotelId为{}mtHotelId为{}mtGoodId为{}mtRoomId{}", masterHotelId, mtHotelId, mtGoodId, mtRoomId);
            RoomDataEntityVo roomDataEntityVo = roomStatus(validPriceVo.getRoomId(), validPriceVo.getHotelId(), masterHotelId, mtHotelId, mtGoodId, mtRoomId, validPriceVo.getTime(), 0);
            roomDataEntityVos.add(roomDataEntityVo);
            BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
            batchPushRoomVo.setHotelId(validPriceVo.getHotelId());
            batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
            //调用直连推送房态
            Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
            SendUtils.dingMsg("下单前效验-直连推送报价等数据接口酒店id" + batchPushRoomVo.getHotelId(), "请求状态" + result.getMsg().toString(), 1, restTemplate);
            if (result.getCode() == CommonConstants.SUCCESS) {
                Map<String, String> resultData = result.getData();
                for (SwitchPushRoomDataAllEntity pushRoomDataEntity : switchPushStatusEntities) {
                    pushRoomDataEntity.setLogKey(resultData.get("logKey"));
                    pushRoomDataEntity.setRemark("房态变更");
                    pushRoomDataEntity.setStatus(0);
                }
                //添加记录
                addLogToPushLog(switchPushStatusEntities);
            }
            return new Result<>(SwitchValidPriceStatusEnums.PRICE.getCode(), SwitchValidPriceStatusEnums.PRICE.getMsg());
        }
        log.info("=============下单前效验携程的订单总价 美团的订单总价通过===========================");
        return new Result<>(SwitchValidPriceStatusEnums.SUCCESS.getCode(), SwitchValidPriceStatusEnums.SUCCESS.getMsg());
    }


    /**
     * @author: lmf
     * @date: 2020/8/17 17:34
     * 判断该售卖房型是否处于天天特价之内,如果是按照含有标签的价格公式
     */
    public SwitchHotelActiveTagEntity isJoinActiveTag(int hotelId, int roomId, String time) {
        log.info("=============促销活动数据===========");
        return switchHotelActiveTagMapper.selectHotelIdAndRoomIdAndTime(hotelId, roomId, time);
    }

    /**
     * @author: lmf
     * @date: 2020/8/28 10:36
     * 使用内部类来记录日志
     */
    class AddLogToCallable implements Callable<Result<Object>> {
        String threadName;
        List<SwitchPushRoomDataAllEntity> switchPushRoomDataEntities;

        public AddLogToCallable(String threadName, List<SwitchPushRoomDataAllEntity> switchPushRoomDataEntities) {
            this.threadName = threadName;
            this.switchPushRoomDataEntities = switchPushRoomDataEntities;

        }

        @Override
        public Result<Object> call() {
            //添加记录
            addLogToPushLog(switchPushRoomDataEntities);
            return new Result<>();
        }
    }

    /**
     * @author: lmf
     * @date: 2020/9/3 16:35
     * 为参与促销标签活动的酒店重新推送价格
     */
    @Override
    public Result<Object> pushActiveTagPrice(Integer hotelId, List<Integer> roomIds) {
        if (ObjectUtils.isEmpty(roomIds) || roomIds.size() < 1) {
            log.info("===============为参与促销活动的酒店重新推送价格失败=========================");
            return new Result<>("推送失败");
        }
        int day=3;
        if(redisService.exists(CommonConstants.SWITCH_PUSH_DATA_DAY)){
            day= (int) redisService.get(CommonConstants.SWITCH_PUSH_DATA_DAY);
        }
        log.info("===========因为参与天天特价进行价格重新推送,涉及的房型id有为{}===============", JSON.toJSONString(roomIds));
        //5.封装房型推送数据实体
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        for (Integer roomId : roomIds) {
            Map<String, Object> params = new HashMap<>();
            params.put("days", day);
            //1.获取对应的产品id
            SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectGoods(hotelId, roomId);
            if (ObjectUtils.isEmpty(switchCreateRoomEntity)) {
                log.info("============找不到相应的创建售卖房型记录，请检查售卖房型id正确=======");
                continue;
            }
            int mtGoodId = switchCreateRoomEntity.getMtGoodId();
            //2.获取美团房价
            params.put("goodsId", mtGoodId);
            List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = getMtGoodsPrice(params);
            if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
                log.info("美团的产品价格日历数据为空");
                return new Result<>("美团的产品价格日历数据为空");
            }
            BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
            batchPushRoomVo.setHotelId(hotelId);
            List<RoomDataEntityVo> roomDataEntityVo = new ArrayList<>();
            try {
                roomDataEntityVo = roomDataEntityVoByPrice(switchCreateRoomEntity, mtHotelGoodsPriceBaseDetailVos);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (ObjectUtils.isEmpty(roomDataEntityVo) || roomDataEntityVo.size() < 1) {
                continue;
            } else {
                roomDataEntityVos.addAll(roomDataEntityVo);
            }
        }
        BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
        batchPushRoomVo.setHotelId(hotelId);
        if (ObjectUtils.isEmpty(roomDataEntityVos) || roomDataEntityVos.size() < 1) {
            return new Result<>("推送的数据实体为空");
        }
        List<List<RoomDataEntityVo>> RoomDataEntityVoLists = ListUtils.parititon(roomDataEntityVos, 298);
        log.info("==========分割后的list长度为{}============", RoomDataEntityVoLists.size());
        for (List<RoomDataEntityVo> roomDataEntityVos1 : RoomDataEntityVoLists) {
            batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos1);
            Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
            if (result.getCode() == CommonConstants.SUCCESS) {
                log.info("============推送完成=================");
            }
        }
        return new Result<>("成功");
    }

    /**
     * @author: lmf
     * @date: 2020/9/13 16:55
     * 重新推送一个月的价格
     */
    public List<RoomDataEntityVo> roomDataEntityVoByPrice(SwitchCreateRoomEntity switchCreateRoomEntity, List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos) throws InvocationTargetException, IllegalAccessException {
        log.info("=================获取酒店上架价格配置start===================");
        Map<String, List<SwitchPriceBaseSetEntity>> priceSetMap = getOnlinePriceSet();
        log.info("=================获取酒店上架价格配置end===================");
        log.info("==============创建推送价格实体=======================");
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        //遍历美团价格
        for (MtHotelGoodsPriceBaseDetailVo mtHotelGoodsPriceBaseDetailVo : mtHotelGoodsPriceBaseDetailVos) {
            //携程
            RoomDataEntityVo roomDataEntityVo = new RoomDataEntityVo();
            roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //去哪儿
            RoomDataEntityVo qunarRoomDataEntityVo = new RoomDataEntityVo();
            qunarRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //B2B
            RoomDataEntityVo b2bRoomDataEntityVo = new RoomDataEntityVo();
            b2bRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //channelA
            RoomDataEntityVo channelaRoomDataEntityVo = new RoomDataEntityVo();
            channelaRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //针对统一的进行价格公式计算
            Map<String, Object> map = new HashMap<>();
            //判断是否参加促销活动
            SwitchHotelActiveTagEntity switchHotelActiveTagEntity = switchHotelActiveTagMapper.selectHotelIdAndRoomIdAndTime(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(), mtHotelGoodsPriceBaseDetailVo.getDate());
            if (ObjectUtils.isEmpty(switchHotelActiveTagEntity)) {
                log.info("============该房型在{}没有参与促销活动========", mtHotelGoodsPriceBaseDetailVo.getDate());
                map = getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), null);
            } else {
                String currentWeekDay = DateUtil.dayForWeek(mtHotelGoodsPriceBaseDetailVo.getDate());
                //促销
                if (!ObjectUtils.isEmpty(switchHotelActiveTagEntity)&&DateUtil.commpareDay(switchHotelActiveTagEntity.getStartTime(),mtHotelGoodsPriceBaseDetailVo.getDate())&&DateUtil.commpareDay(mtHotelGoodsPriceBaseDetailVo.getDate(),switchHotelActiveTagEntity.getEndTime())) {
                    log.info("==============该房型在{}有参与活动,活动数据为{}========",mtHotelGoodsPriceBaseDetailVo.getDate(), JSON.toJSONString(switchHotelActiveTagEntity));
                    map = getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), switchHotelActiveTagEntity);
                } else {//判断当前周几，是否符合促销活动
                    map = getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), null);
                }
            }
            //如果价格符合公式，房态可预定 有库存就进行设置推送
            float price = Float.parseFloat(map.get("ctripPrice").toString());
            float channelPrice = Float.parseFloat(map.get("qunarPrice").toString());
            //房价推送实体
            //携程
            roomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            roomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //去哪儿
            qunarRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            qunarRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //b2b
            b2bRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            b2bRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //channelA
            channelaRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            channelaRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //携程房价实体
            RoomPriceModelVo roomPriceModelVo = new RoomPriceModelVo();
            roomPriceModelVo.setRoomPrice(price);
            roomPriceModelVo.setCurrency("CNY");
            //去哪儿房价实体
            RoomPriceModelVo qunarroomPriceModelVo = new RoomPriceModelVo();
            qunarroomPriceModelVo.setRoomPrice(channelPrice);
            qunarroomPriceModelVo.setCurrency("CNY");
            //b2b房价实体
            RoomPriceModelVo b2broomPriceModelVo = new RoomPriceModelVo();
            //channel房价实体
            RoomPriceModelVo channelroomPriceModelVo = new RoomPriceModelVo();
            //渠道名称
            String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
            String QunarChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
            String b2bChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
            /*String channelChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_CHANNEL_A.getName());*/
            //BeanUtils.copyProperties(qunarroomPriceModelVo,roomPriceModelVo);
            BeanUtils.copyProperties(b2broomPriceModelVo, qunarroomPriceModelVo);
            BeanUtils.copyProperties(channelroomPriceModelVo, qunarroomPriceModelVo);
            //携程
            roomPriceModelVo.setChannel(channel);
            roomDataEntityVo.setRoomPriceModel(roomPriceModelVo);
            //去哪儿
            qunarroomPriceModelVo.setChannel(QunarChannel);
            qunarRoomDataEntityVo.setRoomPriceModel(qunarroomPriceModelVo);
            //b2b
            b2broomPriceModelVo.setChannel(b2bChannel);
            b2bRoomDataEntityVo.setRoomPriceModel(b2broomPriceModelVo);
            //channelA
            /*channelroomPriceModelVo.setChannel(channelChannel);
            channelaRoomDataEntityVo.setRoomPriceModel(channelroomPriceModelVo);*/
            roomDataEntityVos.add(b2bRoomDataEntityVo);
            /*roomDataEntityVos.add(channelaRoomDataEntityVo);*/
            roomDataEntityVos.add(roomDataEntityVo);
            roomDataEntityVos.add(qunarRoomDataEntityVo);
        }
        return roomDataEntityVos;
    }

    /**
     * @author: lmf
     * @date: 2020/9/8 14:16
     * 多线程推送房态放量
     */
    @Override
    public Result<Object> pushDataByThead() {

   /*     //1.获取创建的子酒店
        List<SwitchCreateSubHotelEntity> switchCreateSubHotelEntities=switchCreateSubHotelMapper.selectByState();
        //遍历子酒店id
        tab:for(SwitchCreateSubHotelEntity switchCreateSubHotelEntity:switchCreateSubHotelEntities){
            List<SwitchCreateRoomEntity> switchCreateRoomEntities=switchCreateRoomMapper.selectByHotelId(switchCreateSubHotelEntity.getSubHotelId());
            if(ObjectUtils.isEmpty(switchCreateRoomEntities)||switchCreateRoomEntities.size()<1){
                continue tab;
            }
            int i=0;
            stab:for(SwitchCreateRoomEntity switchCreateRoomEntity:switchCreateRoomEntities){
                String key=switchCreateRoomEntity.getHotelId()+"--"+switchCreateRoomEntity.getRoomId();
                if(redisService.exists(key)){
                    i++;
                    continue stab;
                }
                Result<Object> result=pushRoomData(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(),1);
                redisService.set(key,1,(long)2000);
                if(result.getCode()==CommonConstants.SUCCESS){
                    log.info("===============推送成功,oh yes===========");
                }
            }
            if(i==switchCreateRoomEntities.size()){
                continue tab;
            }
            log.info(">>>>设置子酒店售卖状态 start");
            Map<String, Object> updateChannelVoMap = new HashMap<>();
            updateChannelVoMap.put("hotelIDs", new int[]{switchCreateSubHotelEntity.getSubHotelId()});
            updateChannelVoMap.put("cBookable", SwitchChannelEnums.SALE.getCode());//默认停售
            updateChannelVoMap.put("qBookable", SwitchChannelEnums.SALE.getCode());//默认停售
            updateChannelVoMap.put("channelABookable", SwitchChannelEnums.SALE.getCode());//默认停售
            updateChannelVoMap.put("b2bBookable", SwitchChannelEnums.SALE.getCode());//默认停售

            log.info(">>>>updateChannelVoMap{}",updateChannelVoMap);
            Result<Object> setHotelSupplierBookableResult = switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());

            //接口调用失败
            if(setHotelSupplierBookableResult.getCode() != CommonConstants.SUCCESS){
                log.info(">>>>设置子酒店售卖状态：接口调用失败");
                return setHotelSupplierBookableResult;
            }
            log.info(">>>>设置子酒店售卖状态 end");
           ***********设置子酒店售卖状态 end***********
            try {
                Thread.sleep(6000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        */
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectAll();
        tab:
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            String key = switchCreateRoomEntity.getHotelId() + "-12313-" + switchCreateRoomEntity.getRoomId();
          /*  if(redisService.exists(key)){
                continue tab;
            }*/
            Result<Object> result = pushRoomByIntentory(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId());
            if (result.getCode() == CommonConstants.SUCCESS) {
                redisService.set(key, 1, (long) 2000);
                log.info("===============推送成功,oh yes===========");
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
        return null;
    }

    /**
     * 从新推送一个月的库存
     */
    public Result<Object> pushRoomByIntentory(int hotelId, int basicRoomTypeId) {
        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectGoods(hotelId, basicRoomTypeId);
        if (ObjectUtils.isEmpty(switchCreateRoomEntity)) {
            log.info("============找不到相应的创建售卖房型记录，请检查售卖房型id正确=======");
            return new Result<>();
        }
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        //携程
        RoomDataEntityVo roomDataEntityVo = new RoomDataEntityVo();
        roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        roomDataEntityVo.setStartDate("2020-09-10");
        roomDataEntityVo.setEndDate("2020-10-10");
        //渠道名称
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        //房量推送实体
        RoomInventoryModelVo roomInventoryModelVo = new RoomInventoryModelVo();
        roomInventoryModelVo.setPreservedQuantity(0);
        roomInventoryModelVo.setUnPreservedQuantity(1);
        roomInventoryModelVo.setPushPreservedType(3);
        roomInventoryModelVo.setPushUnPreservedType(3);
        roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
        roomInventoryModelVo.setChannel(channel);
        roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
        roomDataEntityVos.add(roomDataEntityVo);
        BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
        batchPushRoomVo.setHotelId(hotelId);
        batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
        Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
        if (result.getCode() == CommonConstants.SUCCESS) {
            return new Result<>(result.getCode(), "=======推送数据实体成功========");
        } else {
            return new Result<>(result.getMsg());
        }
    }

    /**
     * 从新推送一个月的房态
     */
    public Result<Object> pushRoomByRoomStatus(int hotelId, int basicRoomTypeId) {
        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectGoods(hotelId, basicRoomTypeId);
        if (ObjectUtils.isEmpty(switchCreateRoomEntity)) {
            log.info("============找不到相应的创建售卖房型记录，请检查售卖房型id正确=======");
            return new Result<>();
        }
        int day=15;
        if(redisService.exists(CommonConstants.SWITCH_PUSH_DATA_DAY)){
            day= (int) redisService.get(CommonConstants.SWITCH_PUSH_DATA_DAY);
        }
        Map<String, Object> params = new HashMap<>();
        params.put("days", day);
        //3.获取美团的房态
        params.put("hotelId", switchCreateRoomEntity.getMtHotelId());
        List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos = getMtGoodsStatus(params, switchCreateRoomEntity.getMtGoodId());
        log.info("===============房态的数据长度为ss{}======", mtHotelGoodsStatusDetailStateVos.size());
        if (mtHotelGoodsStatusDetailStateVos.size() < 1) {
            return new Result<>();
        }
        //渠道名称
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        for (MtHotelGoodsStatusDetailStateVo mtHotelGoodsStatusDetailStateVo : mtHotelGoodsStatusDetailStateVos) {
            RoomDataEntityVo roomDataEntityVo = new RoomDataEntityVo();
            //房态推送实体
            RoomStatusModelVo roomStatusModelVo = new RoomStatusModelVo();
            roomStatusModelVo.setChannel(channel);
            if (mtHotelGoodsStatusDetailStateVo.getStatus() == 1) {
                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
            } else {
                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
            }
            roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
            roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            roomDataEntityVo.setStartDate(mtHotelGoodsStatusDetailStateVo.getDate());
            roomDataEntityVo.setEndDate(mtHotelGoodsStatusDetailStateVo.getDate());
            roomDataEntityVos.add(roomDataEntityVo);
        }
        BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
        batchPushRoomVo.setHotelId(hotelId);
        batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
        Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
        if (result.getCode() == CommonConstants.SUCCESS) {
            return new Result<>(result.getCode(), "=======推送数据实体成功========");
        } else {
            return new Result<>(result.getMsg());
        }
    }

    /**
     * @author: lmf
     * @date: 2020/9/14 16:41
     * 为所有售卖房型推送一个月的价格,因为价格配置
     */
    @Override
    public Result<Object> pushRoomPriceByNewRate() {
        log.info("===========为所有售卖房型推送一个月的价格,因为价格配置==============");
        //1.先获取所有的子酒店列表
        List<SwitchCreateSubHotelEntity> switchCreateSubHotelEntities = switchCreateSubHotelMapper.selectSaleHotelList();
        //获取的酒店列表
        if(ObjectUtils.isEmpty(switchCreateSubHotelEntities)||switchCreateSubHotelEntities.size()<1){
            log.info("=========没有售卖的酒店可以进行推送========");
            return new Result<>();
        }
        subTab:
        for (SwitchCreateSubHotelEntity switchCreateSubHotelEntity : switchCreateSubHotelEntities) {
            //2.获取所有的售卖房型id
            List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectByHotelId(switchCreateSubHotelEntity.getSubHotelId());
            int day=3;
            if(redisService.exists(CommonConstants.SWITCH_PUSH_DATA_DAY)){
                day= (int) redisService.get(CommonConstants.SWITCH_PUSH_DATA_DAY);
            }
            //5.封装房型推送数据实体
            List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
            label:
            for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                Map<String, Object> params = new HashMap<>();
                params.put("days", day);
                int mtGoodId = switchCreateRoomEntity.getMtGoodId();
                //2.获取美团房价
                params.put("goodsId", mtGoodId);
                List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = getMtGoodsPrice(params);
                if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
                    log.info("美团的产品价格日历数据为空");
                    return new Result<>("美团的产品价格日历数据为空");
                }
                List<RoomDataEntityVo> roomDataEntityVo = new ArrayList<>();
                try {
                    roomDataEntityVo = roomDataEntityVoByPrice(switchCreateRoomEntity, mtHotelGoodsPriceBaseDetailVos);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (ObjectUtils.isEmpty(roomDataEntityVo) || roomDataEntityVo.size() < 1) {
                    continue label;
                } else {
                    roomDataEntityVos.addAll(roomDataEntityVo);
                }
            }
            BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
            batchPushRoomVo.setHotelId(switchCreateSubHotelEntity.getSubHotelId());
            List<List<RoomDataEntityVo>> RoomDataEntityVoLists = ListUtils.parititon(roomDataEntityVos, 298);
            log.info("==========分割后的list长度为{}============", RoomDataEntityVoLists.size());
            int size = 0;
            for (List<RoomDataEntityVo> roomDataEntityVos1 : RoomDataEntityVoLists) {
                batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos1);
                Result<Object> result = pushRoom(batchPushRoomVo);
            }

        }
        return new Result<>("推送成功");
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/22
     * 为指定的售卖房型重新推送价格房态
     */
    @Override
    public Result<Object> pushBySpecial() {
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectAll();
        //5.封装房型推送数据实体
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            //先设置为上线
            //modifyRoomStatus(switchCreateRoomEntity.getRoomId(),switchCreateRoomEntity.getHotelId(), 1);
            //然后在进行价格房态推送
            pushRoomDataNew(switchCreateRoomEntity);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        log.info("======为指定的售卖房型重新推送价格房态完成======================");
        return null;
    }

    /**
     * 下架售卖房型
     *
     * @param roomId  售卖房型id
     * @param hotelId 子酒店id
     */
    public void modifyRoomStatus(int roomId, int hotelId, int status) {
        //没有库存,下架该售卖房型
        SetRoomOnlineOfflineVo setRoomOnlineOfflineVo = new SetRoomOnlineOfflineVo();
        setRoomOnlineOfflineVo.setRoomTypeId(roomId);
        setRoomOnlineOfflineVo.setHotelId(hotelId);
        setRoomOnlineOfflineVo.setRoomStatus(status);
        setRoomOnlineOfflineVo.setChannel(StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName()));
        Result<Object> result = switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
        if (result.getCode() == CommonConstants.SUCCESS) {
            setRoomOnlineOfflineVo.setChannel(StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName()));
            Result<Object> result1 = switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
            log.info("==============设置酒店上线的结果为{}",result1.getMsg());
            if (result1.getCode() == CommonConstants.SUCCESS) {
                SwitchRoomOnlineOfflineLogEntity switchRoomOnlineOfflineLogEntity = new SwitchRoomOnlineOfflineLogEntity();
                switchRoomOnlineOfflineLogEntity.setId(StringUtil.getUUID());
                switchRoomOnlineOfflineLogEntity.setHotelId(roomId);
                switchRoomOnlineOfflineLogEntity.setRoomId(hotelId);
                switchRoomOnlineOfflineLogEntity.setCreateTime(new Date());
                switchRoomOnlineOfflineLogMapper.insert(switchRoomOnlineOfflineLogEntity);
                //修改售卖房型的售卖状态状态
                //switchCreateRoomMapper.updateByRoomId(roomId,1);
                // switchCreateRoomMapper.deleteByHotelIdAndRoomId(hotelId, roomId);
            }
        }
    }

    @Transactional
    public Result<Object> pushRoomDataNew(SwitchCreateRoomEntity switchCreateRoomEntity) {
        //1.获取对应的产品id
        //获取该房型推送最后一天的日期
        SwitchPushRoomDataEntity switchPushRoomDataEntity = switchPushRoomDataMapper.getLastPushDate(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId());
        int day=15;
        if(redisService.exists(CommonConstants.SWITCH_PUSH_DATA_DAY)){
            day= (int) redisService.get(CommonConstants.SWITCH_PUSH_DATA_DAY);
        }
        Map<String, Object> params = new HashMap<>();
        String endTime=DateUtil.getNextDays(day);
        //如果不存在说明第一次推送房量，此时库存应该是add
        params.put("days", day);
        int mtGoodId = switchCreateRoomEntity.getMtGoodId();
        int mtHotelId = switchCreateRoomEntity.getMtHotelId();
        int mtRoomId = Integer.valueOf(switchCreateRoomEntity.getMtRoomId());
        //2.获取美团房价
        params.put("goodsId", mtGoodId);
        List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = getMtGoodsPrice(params);
        if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
            log.info("美团的产品价格日历数据为空");
            return new Result<>("美团的产品价格日历数据为空");
        }
        //3.获取美团的房态
        params.put("hotelId", mtHotelId);
        List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos = getMtGoodsStatus(params, mtGoodId);
        log.info("===============房态的数据长度为ss{}======", mtHotelGoodsStatusDetailStateVos.size());
        if (mtHotelGoodsStatusDetailStateVos.size() < 1) {
            mtHotelGoodsStatusDetailStateVos = new ArrayList<>();
        }
        //4.获取美团的产品库存
        params.put("roomId", mtRoomId);
        MtHotelGoodsInventoryVo mtHotelGoodsInventoryVo = getMtGoodsInventory(params);
        if (ObjectUtils.isEmpty(mtHotelGoodsInventoryVo)) {
            log.info("美团的产品库存为空");
            return new Result<>("美团的产品库存为空");
        }
        BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
        batchPushRoomVo.setHotelId(switchCreateRoomEntity.getHotelId());
        //5.封装房型推送数据实体
        List<RoomDataEntityVo> roomDataEntityVos = null;
        try {
            roomDataEntityVos = roomDataEntityVoV2(switchCreateRoomEntity, mtHotelGoodsPriceBaseDetailVos, mtHotelGoodsStatusDetailStateVos, endTime,null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (ObjectUtils.isEmpty(roomDataEntityVos) || roomDataEntityVos.size() < 1) {
            log.info("推送的实体数据为空");
            return new Result<>("推送的实体数据为空");
        }
        batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
        log.info("==============推送的房型数据实体为{}====================", roomDataEntityVos);
        Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
        if(result.getCode() == CommonConstants.SUCCESS||result.getMsg().toString().contains("数据重复")){
            switchPushRoomDataMapper.deleteByRoomId(switchCreateRoomEntity.getRoomId());
            //如果有日志记录再进行操作
            switchPushRoomDataEntity=new SwitchPushRoomDataEntity();
            switchPushRoomDataEntity.setCreateTime(new Date());
            switchPushRoomDataEntity.setHotelId(batchPushRoomVo.getHotelId());
            switchPushRoomDataEntity.setRoomId(switchCreateRoomEntity.getRoomId());
            switchPushRoomDataEntity.setId(StringUtil.getUUID());
            switchPushRoomDataEntity.setMasterHotelId(switchCreateRoomEntity.getMasterHotelId());
            switchPushRoomDataEntity.setModifyTime(new Date());
            switchPushRoomDataEntity.setMtGoodId(switchCreateRoomEntity.getMtGoodId());
            switchPushRoomDataEntity.setMtHotelId(switchCreateRoomEntity.getMtHotelId());
            switchPushRoomDataEntity.setMtRoomId(Integer.valueOf(switchCreateRoomEntity.getMtRoomId()));
            switchPushRoomDataEntity.setStartTime(endTime);
            switchPushRoomDataMapper.insert(switchPushRoomDataEntity);
        }
        return new Result<>();
    }

    /**
     * 初始化房型数量
     * @return
     */
    @Override
    public Result<Object> initRoomNum() {
        //1.获取创建的子酒店
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        List<SwitchCreateSubHotelEntity> switchCreateSubHotelEntities=switchCreateSubHotelMapper.selectAll();
        //遍历子酒店id
        tab:for(SwitchCreateSubHotelEntity switchCreateSubHotelEntity:switchCreateSubHotelEntities){
            //获取酒店的所有售卖房型列表
            List<SwitchCreateRoomEntity> switchCreateRoomEntities=switchCreateRoomMapper.selectByHotelId(switchCreateSubHotelEntity.getSubHotelId());
            if(ObjectUtils.isEmpty(switchCreateRoomEntities)||switchCreateRoomEntities.size()<1){
                continue tab;
            }
            BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
            batchPushRoomVo.setHotelId(switchCreateSubHotelEntity.getSubHotelId());
            RoomDataEntityVo roomDataEntityVo;
            List<RoomDataEntityVo> roomDataEntityVos=new ArrayList<>();
            for(SwitchCreateRoomEntity switchCreateRoomEntity:switchCreateRoomEntities){
                roomDataEntityVo = new RoomDataEntityVo();
                roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
                RoomInventoryModelVo roomInventoryModelVo=new RoomInventoryModelVo();
                roomInventoryModelVo.setPreservedQuantity(0);
                roomInventoryModelVo.setUnPreservedQuantity(1);
                roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                roomInventoryModelVo.setChannel(channel);
                roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                Calendar calendar = Calendar.getInstance();
                long createTime = calendar.getTimeInMillis();
                SimpleDateFormat form1 = new SimpleDateFormat("yyyy-MM-dd");
                String now = form1.format(createTime);
                calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 7);
                Date today = calendar.getTime();
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                String sen = format.format(today);
                roomDataEntityVo.setStartDate(now);
                roomDataEntityVo.setEndDate(sen);
                roomDataEntityVos.add(roomDataEntityVo);
            }

            batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
            Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
            if(result.getCode()==CommonConstants.SUCCESS){
                log.info("=============推送成功,推送结果{}=====================",result.getMsg());
            }else{
                log.info("=============推送成功,推送结果{}=====================",result.getMsg());
            }
            try {
                Thread.sleep(6000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            roomDataEntityVos.clear();
        }
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/30
     * 更新取消规则
     */
    @SneakyThrows
    @Override
    public Result<Object> pushRoomCancelRule(List<MtfpHotelGoodsCancelRuleVo> mtfpHotelGoodsCancelRuleVos) {
        BatchPushRoomVo batchPushRoomVo = null;
        //5.封装房型推送数据实体
        List<RoomDataEntityVo> roomDataEntityVos = null;
        for(MtfpHotelGoodsCancelRuleVo mtfpHotelGoodsCancelRuleVo:mtfpHotelGoodsCancelRuleVos){
            int day=3;
            if(redisService.isMember(CommonConstants.SWITCH_SALE_HOTEL_VIP,mtfpHotelGoodsCancelRuleVo.getMtHotelId())){
                day=getDaysCommonBaseSetForVip();
            }else{
                day=getDaysCommonBaseSetForNormal();
            }
            String endTime=DateUtil.getNextDays(day);
            roomDataEntityVos=new ArrayList<>();
            //1.获取对应的产品id
            SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectRoomInfoByMtHotelIdAndMtHotelRoomIdAndMtGoodId(Integer.parseInt(mtfpHotelGoodsCancelRuleVo.getMtHotelId()),Integer.parseInt(mtfpHotelGoodsCancelRuleVo.getMtRoomId()),Integer.parseInt(mtfpHotelGoodsCancelRuleVo.getMtGoodsId()));
            if (ObjectUtils.isEmpty(switchCreateRoomEntity)) {
                log.info("============找不到相应的创建售卖房型记录，请检查售卖房型id正确=======");
                return new Result<>("找不到相应的创建售卖房型记录，请检查售卖房型id正确");
            }
            batchPushRoomVo=new BatchPushRoomVo();
            batchPushRoomVo.setHotelId(switchCreateRoomEntity.getHotelId());
            //遍历美团的取消规则
            RoomDataEntityVo roomDataEntityVo=new RoomDataEntityVo();
            RoomDataEntityVo quanrRoomDataEntityVo=new RoomDataEntityVo();
            RoomDataEntityVo b2bRoomDataEntityVo=new RoomDataEntityVo();
            //渠道名称
            String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
            String QunarChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
            String b2bChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
            SaleRuleModelVo saleRuleModelVo=new SaleRuleModelVo();
            int isCan=0;
            String time="";
            String key=CommonConstants.SWITCH_CREATE_ROOM_CANCEL_RULE+mtfpHotelGoodsCancelRuleVo.getMtHotelId()+"_"+mtfpHotelGoodsCancelRuleVo.getMtGoodsId()+"_";
            //0 不可取消 1 可以取消
            if(mtfpHotelGoodsCancelRuleVo.getCancelType()==0){
                CtripSellRuleVo ctripSellRuleVo=new CtripSellRuleVo();
                ctripSellRuleVo.setCancelType(1);
                saleRuleModelVo.setCtripSellRule(ctripSellRuleVo);
            }else{
                isCan=1;
                CtripSellRuleVo ctripSellRuleVo=new CtripSellRuleVo();
                ctripSellRuleVo.setCancelType(2);
                //提前取消时间类型 0 时间  1 时间量
                if(mtfpHotelGoodsCancelRuleVo.getDeductType()==0){
                    ctripSellRuleVo.setLatestCancelTimeOfDays((mtfpHotelGoodsCancelRuleVo.getAheadCancelDays()>0)?mtfpHotelGoodsCancelRuleVo.getAheadCancelDays():0);
                    ctripSellRuleVo.setLatestCancelTimeOfHours(Integer.parseInt(Arrays.stream(mtfpHotelGoodsCancelRuleVo.getAheadCancelHours().split(":")).findFirst().get()));
                    ctripSellRuleVo.setOverduePaymentType("C");
                }else{
                    ctripSellRuleVo.setLatestCancelTimeOfDays((mtfpHotelGoodsCancelRuleVo.getAheadCancelDays()>0)?mtfpHotelGoodsCancelRuleVo.getAheadCancelDays():0);
                    int hours=Integer.parseInt(mtfpHotelGoodsCancelRuleVo.getAheadCancelHours());
                    ctripSellRuleVo.setLatestCancelTimeOfHours(24-hours);
                    ctripSellRuleVo.setOverduePaymentType("C");
                }
                time=mtfpHotelGoodsCancelRuleVo.getAheadCancelDays()+"_"+mtfpHotelGoodsCancelRuleVo.getAheadCancelHours();
                saleRuleModelVo.setCtripSellRule(ctripSellRuleVo);
            }
            saleRuleModelVo.setChannel(channel);
            roomDataEntityVo.setSaleRuleModel(saleRuleModelVo);
            SaleRuleModelVo qunarSaleRuleModelVo=new SaleRuleModelVo();
            BeanUtils.copyProperties(qunarSaleRuleModelVo,saleRuleModelVo);
            SellingRuleVo sellingRuleVo=new SellingRuleVo();
            sellingRuleVo.setLatestconfirmDate(18);
            sellingRuleVo.setLatestconfirmTimeOfDays(0);
            sellingRuleVo.setLatestconfirmTimeOfHours(23);
            qunarSaleRuleModelVo.setSellingRule(sellingRuleVo);
            qunarSaleRuleModelVo.setChannel(QunarChannel);
            SaleRuleModelVo b2bSaleRuleModelVo=new SaleRuleModelVo();
            BeanUtils.copyProperties(b2bSaleRuleModelVo,saleRuleModelVo);
            b2bSaleRuleModelVo.setSellingRule(sellingRuleVo);
            b2bSaleRuleModelVo.setChannel(b2bChannel);
            roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            roomDataEntityVo.setStartDate(sdf.format(new Date()));
            roomDataEntityVo.setEndDate(endTime);
            quanrRoomDataEntityVo.setSaleRuleModel(qunarSaleRuleModelVo);
            quanrRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            quanrRoomDataEntityVo.setStartDate(sdf.format(new Date()));
            quanrRoomDataEntityVo.setEndDate(endTime);
            log.info("=================saleRuleModelVo的数据为{}",saleRuleModelVo);
            roomDataEntityVo.setSaleRuleModel(saleRuleModelVo);
            log.info("======roomDataEntityVo的数据为{}====", JSON.toJSONString(roomDataEntityVo));
            roomDataEntityVos.add(roomDataEntityVo);
            b2bRoomDataEntityVo.setStartDate(sdf.format(new Date()));
            b2bRoomDataEntityVo.setEndDate(endTime);
            b2bRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            b2bRoomDataEntityVo.setSaleRuleModel(b2bSaleRuleModelVo);
            //  roomDataEntityVos.add(quanrRoomDataEntityVo);
            //  roomDataEntityVos.add(b2bRoomDataEntityVo);
            //对日期时间相同的价格进行合并
            batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
            batchPushRoomVo.setHotelId(switchCreateRoomEntity.getHotelId());
            log.info("==============推送的房型数据实体为{}====================", roomDataEntityVos);
            Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
            if(result.getCode() == CommonConstants.SUCCESS){
                //更新缓存
                key=key+isCan;
                if(isCan==0){
                    redisService.set(key+isCan,"0");
                }else{
                    redisService.set(key+isCan,time);
                }
            }
        }
        return new Result<>();
    }
}

